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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.