File: hash_object.t

package info (click to toggle)
libclass-makemethods-perl 1.01-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,944 kB
  • sloc: perl: 10,495; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

package Y;
sub new { bless { foo => 'foo', bar => 'bar' }, shift; }
sub foo { shift->{'foo'}; }
sub bar {
  my ($self, $new) = @_;
  defined $new and $self->{'bar'} = $new;
  $self->{'bar'};
}

package X;

use Test;
BEGIN { plan tests => 11 }

use Class::MakeMethods::Template::Hash
  object  => [ 
    '--get_set_init',
    '-class' => 'Y',
    'a',
    [ qw / b c d / ],
    {
      name => 'e',
      delegate => [ qw / foo / ],
    },
    {
      name => 'f',
      delegate => [ qw / bar / ],
    }
  ];

sub new { bless {}, shift; }
my $o = new X;

ok( 1 ); #1

ok( ref $o->a eq 'Y' ); #2
ok( ref $o->b eq 'Y' ); #3

my $y = new Y;
ok( $o->c($y) ); #4
ok( $o->c eq $y ); #5
ok( ref $o->c eq 'Y' ); #6

ok( ref $o->e eq 'Y' ); #7

ok( $o->foo eq 'foo' ); #8
ok( $o->bar('bar') ); #9
ok( $o->bar eq 'bar' ); #10

ok( $o->e->foo eq $o->foo ); #11

exit 0;