~ubuntu-branches/ubuntu/jaunty/libglib-perl/jaunty

« back to all changes in this revision

Viewing changes to t/tied_definedness.t

  • Committer: Bazaar Package Importer
  • Author(s): Marc 'HE' Brockschmidt
  • Date: 2008-03-15 09:40:14 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080315094014-af0fqrtad5fq1u0f
Tags: 1:1.181-1
New upstream release (only changes in the build system irrelevant for
Debian, but for completeness' sake...)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# This is based on a test case sent to gtk-perl-list by Giuliano.
 
4
 
 
5
package ClassFoo;
 
6
use strict;
 
7
use warnings;
 
8
use Glib;
 
9
 
 
10
use Glib::Object::Subclass
 
11
  Glib::Object::,
 
12
  properties => [
 
13
    Glib::ParamSpec->boxed('title',
 
14
                           'title',
 
15
                           'The title',
 
16
                           'Glib::Scalar',
 
17
                           [qw/writable readable/]),
 
18
  ];
 
19
 
 
20
sub INIT_INSTANCE {
 
21
    my $self = shift;
 
22
    $self->{prop_title} = undef;
 
23
}
 
24
 
 
25
sub SET_PROPERTY {
 
26
    my ($self, $pspec, $val) = @_;
 
27
    my $propname = $pspec->get_name;
 
28
    if ($propname eq 'title') {
 
29
        $self->{prop_title} = $val;
 
30
    } else {
 
31
        die "unknown property ``$propname''";
 
32
    }
 
33
}
 
34
 
 
35
sub GET_PROPERTY {
 
36
    my ($self, $pspec) = @_;
 
37
    my $propname = $pspec->get_name;
 
38
    if ($propname eq 'title') {
 
39
        return $self->{prop_title};
 
40
    } else {
 
41
        die "unknown property ``$propname''";
 
42
    }
 
43
}
 
44
 
 
45
# --------------------------------------------------------------------------- #
 
46
 
 
47
package main;
 
48
use strict;
 
49
use warnings;
 
50
use Tie::Hash;
 
51
use Test::More tests => 1;
 
52
 
 
53
my $hashref = {};
 
54
tie %$hashref, 'Tie::StdHash';
 
55
$hashref->{Title} = 'foo';
 
56
 
 
57
my $w = ClassFoo->new;
 
58
$w->set_property ('title', $hashref->{Title});
 
59
is ($w->get_property ('title'), $hashref->{Title});