File: hash_array_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 (31 lines) | stat: -rw-r--r-- 615 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
#!/usr/bin/perl

package Y;
my $count = 0;
sub new { bless { id => $count++ }, shift; }
sub id { shift->{id}; }

package X;

use Test;
BEGIN { plan tests => 8 }

use Class::MakeMethods::Template::Hash (
  array_of_objects  => [ '-class' => 'Y', { name => 'a', delegate => 'id' } ],
);

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

ok( 1 ); #1

ok( $o->push_a (Y->new) ); #2
ok( $o->push_a (Y->new) ); #3
ok( $o->pop_a->id == 1  ); #4
ok( $o->push_a (Y->new) ); #5
ok do { @b = $o->a; @b == 2 }; #6
ok( join (' ', $o->id) eq '0 2' ); #7
ok do { $a = 1; for ($o->a) { $a &&= ( ref ($_) eq 'Y' ) }; $a }; #8

exit 0;