Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Moose::Role not getting params passed via ->new() by italdesign

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-18 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found