File: tied_definedness.t

package info (click to toggle)
libglib-perl 1%3A1.190-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,024 kB
  • ctags: 222
  • sloc: perl: 3,135; ansic: 577; makefile: 53
file content (59 lines) | stat: -rw-r--r-- 1,305 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl

# This is based on a test case sent to gtk-perl-list by Giuliano.

package ClassFoo;
use strict;
use warnings;
use Glib;

use Glib::Object::Subclass
  Glib::Object::,
  properties => [
    Glib::ParamSpec->boxed('title',
                           'title',
                           'The title',
                           'Glib::Scalar',
                           [qw/writable readable/]),
  ];

sub INIT_INSTANCE {
    my $self = shift;
    $self->{prop_title} = undef;
}

sub SET_PROPERTY {
    my ($self, $pspec, $val) = @_;
    my $propname = $pspec->get_name;
    if ($propname eq 'title') {
        $self->{prop_title} = $val;
    } else {
        die "unknown property ``$propname''";
    }
}

sub GET_PROPERTY {
    my ($self, $pspec) = @_;
    my $propname = $pspec->get_name;
    if ($propname eq 'title') {
        return $self->{prop_title};
    } else {
        die "unknown property ``$propname''";
    }
}

# --------------------------------------------------------------------------- #

package main;
use strict;
use warnings;
use Tie::Hash;
use Test::More tests => 1;

my $hashref = {};
tie %$hashref, 'Tie::StdHash';
$hashref->{Title} = 'foo';

my $w = ClassFoo->new;
$w->set_property ('title', $hashref->{Title});
is ($w->get_property ('title'), $hashref->{Title});