Activando $Data::Dumper::Deparse podemos ver la forma del
constructor proporcionado:
DB<23> use Data::Dumper
DB<24> $Data::Dumper::Deparse = 1
DB<25> p Dumper(\&Foo::new)
$VAR1 = sub {
package Foo;
use strict 'refs';
my($class, %init) = @_;
$class = 'Foo' unless @_;
my($r) = {};
if (defined $init{'c'}) {
if (ref $init{'c'} eq 'HASH') {
$$r{'Foo::c'} = 'Tutu'->new(%{$init{'c'};});
}
elsif (UNIVERSAL::isa($init{'c'}, 'Tutu')) {
$$r{'Foo::c'} = $init{'c'};
}
else {
croak('Initializer for c must be hash or Tutu reference');
}
}
croak('Initializer for h must be hash reference')
if defined $init{'h'} and ref $init{'h'} ne 'HASH';
$$r{'Foo::h'} = defined $init{'h'} ? $init{'h'} : {};
croak('Initializer for a must be array reference')
if defined $init{'a'} and ref $init{'a'} ne 'ARRAY';
$$r{'Foo::a'} = defined $init{'a'} ? $init{'a'} : [];
$$r{'Foo::s'} = defined $init{'s'} ? $init{'s'} : undef;
bless $r, $class;
};
Casiano Rodríguez León
