File: 15_named_inherit.t

package info (click to toggle)
libhash-fieldhash-perl 0.15-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 1,249; ansic: 207; makefile: 10
file content (68 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download | duplicates (7)
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
60
61
62
63
64
65
66
67
68
#!perl -w

use strict;
use Test::More tests => 8;

use constant VERBOSE => !!$ENV{TEST_VERBOSE};

sub XXX{
	require Data::Dumper;
	my $ddx = Data::Dumper->new(\@_);
	$ddx->Indent(1);
	$ddx->Sortkeys(1);
	diag($ddx->Dump);
}

BEGIN{
	package A;
	use Hash::FieldHash qw(:all);

	fieldhash my %foo, 'foo';
	fieldhash my %bar, 'bar';

	sub new{
		my $class = shift;
		my $obj = bless do{ \my $o }, $class;
		return Hash::FieldHash::from_hash($obj, @_);
	}

	sub dump{
		my($self, $fully_qualify) = @_;
		return $self->to_hash($fully_qualify ? -fully_qualify : undef);
	}

	package B;
	use Hash::FieldHash qw(:all);
	our @ISA = qw(A);

	fieldhash my %baz, 'baz';

	package C;
	use Hash::FieldHash qw(:all);
	our @ISA = qw(B);
}

{
	my $x = B->new('A::foo' => 10, 'A::bar' => 20, 'B::baz' => 30);

	is_deeply $x->dump,    { foo => 10, bar => 20, baz => 30 };
	is_deeply $x->dump(1), { 'A::foo' => 10, 'A::bar' => 20, 'B::baz' => 30 };
}

{
	my $x = C->new('A::foo' => 10, 'A::bar' => 20, 'B::baz' => 30);

	is_deeply $x->dump,    { foo => 10, bar => 20, baz => 30 };
	is_deeply $x->dump(1), { 'A::foo' => 10, 'A::bar' => 20, 'B::baz' => 30 };

	is_deeply $x->dump(0), C->new($x->dump(0))->dump(0);
	is_deeply $x->dump(0), C->new($x->dump(1))->dump(0);
	is_deeply $x->dump(1), C->new($x->dump(0))->dump(1);
	is_deeply $x->dump(1), C->new($x->dump(1))->dump(1);
}

if(VERBOSE){
	if(defined &Hash::FieldHash::_name_registry){
		XXX( Hash::FieldHash::_name_registry() );
	}
}