http://qs1969.pair.com?node_id=1054745

italdesign has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks. Been programming Perl for several years but just stumbled upon Moose. Anyway, I have a script (wget.pl) that instantiates an object of a class (Wget.pm) that uses a role (Transfer.pm). The problem is when I pass a hash ref to Wget->new(), it's not being received correctly. Here is the relevant parts of the code.

wget.pl

use Module::Load; my $class = 'DTF::Wget'; load $class; my $adapter = $class->new( 'input_line' => $input_line, 'dl_base_dir' +=> $dl_base_dir, 'report_file' => $report_file );

Wget.pm

package DTF::Wget; use strict; use warnings; use Moose; with 'DTF::Transfer';

Transfer.pm

package DTF::Transfer; use strict; use warnings; use Moose::Role; sub BUILD {} after 'BUILD' => sub { my $self = shift; die scalar(keys %$self); }

If all worked, the die statement in the role would print 3, since I passed 3 key-value pairs to the constructor of the class that uses the role. However, it prints 0. $self has absolutely nothing. I tried several variations of this, including moving the BUILD to Wget.pm. The result is always the same - $self is empty. I'm probably missing something obvious. Would appreciate any pointers.