9 use Test::More tests => 16;
11 BEGIN { use_ok('fields'); }
16 use fields qw(_no Pants who _up_yours);
19 sub new { fields::new(shift) }
20 sub magic_new { bless [] } # Doesn't 100% work, perl's problem.
24 is_deeply( [sort keys %Foo::FIELDS],
25 [sort qw(_no Pants who _up_yours what)]
29 my($base, $mask) = @_;
31 my $fields = \%{$base.'::FIELDS'};
32 return grep { ($fields::attr{$base}[$fields->{$_}] & $mask) == $mask}
36 is_deeply( [sort &show_fields('Foo', fields::PUBLIC)],
37 [sort qw(Pants who what)]);
38 is_deeply( [sort &show_fields('Foo', fields::PRIVATE)],
39 [sort qw(_no _up_yours)]);
41 # We should get compile time failures field name typos
42 eval q(my Foo $obj = Foo->new; $obj->{notthere} = "");
44 like $@, qr/^No such .*field "notthere"/i;
49 my %test = ( Pants => 'Whatever', _no => 'Yeah',
50 what => 'Ahh', who => 'Moo',
53 $obj->{Pants} = 'Whatever';
55 @{$obj}{qw(what who _up_yours)} = ('Ahh', 'Moo', 'Yip');
57 while(my($k,$v) = each %test) {
63 local $SIG{__WARN__} = sub {
64 return if $_[0] =~ /^Pseudo-hashes are deprecated/
67 eval { $phash = fields::phash(name => "Joe", rank => "Captain") };
69 is( $phash->{rank}, "Captain" );
72 like $@, qr/^Pseudo-hashes have been removed from Perl/;
77 # check if fields autovivify
80 use fields qw(foo bar);
81 sub new { fields::new($_[0]) }
84 my Foo::Autoviv $a = Foo::Autoviv->new();
85 $a->{foo} = ['a', 'ok', 'c'];
86 $a->{bar} = { A => 'ok' };
87 is( $a->{foo}[1], 'ok' );
88 is( $a->{bar}->{A},, 'ok' );
96 my $self = fields::new(shift);
104 my $x = Test::FooBar->new( a => 1, b => 2);
106 is(ref $x, 'Test::FooBar', 'x is a Test::FooBar');
107 ok(exists $x->{a}, 'x has a');
108 ok(exists $x->{b}, 'x has b');