Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: You cannot pass args when calling inner() in Moose?

by Arunbear (Parson)
on Jul 21, 2011 at 16:51 UTC ( #915928=note: print w/ replies, xml ) Need Help??


in reply to You cannot pass args when calling inner() in Moose?

You can pass args e.g. (modified the doc example slightly)

package Document::Page; use Moose; has 'body' => ( is => 'rw', isa => 'Str', default => sub {''} ); sub create { my $self = shift; my $arg = shift; warn $arg; $self->open_page; inner($arg); $self->close_page; } sub append_body { my ( $self, $appendage ) = @_; $self->body( $self->body . $appendage ); } sub open_page { (shift)->append_body('<page>') } sub close_page { (shift)->append_body('</page>') } package Document::PageWithHeadersAndFooters; use Moose; extends 'Document::Page'; augment 'create' => sub { my $self = shift; my $arg = shift; warn $arg; $self->create_header; inner($arg); $self->create_footer; }; sub create_header { (shift)->append_body('<header/>') } sub create_footer { (shift)->append_body('<footer/>') } package TPSReport; use Moose; extends 'Document::PageWithHeadersAndFooters'; augment 'create' => sub { my $self = shift; my $arg = shift; warn $arg; $self->create_tps_report; inner($arg); }; sub create_tps_report { (shift)->append_body('<report type="tps"/>'); } package main; # <page><header/><report type="tps"/><footer/></page> my $report_xml = TPSReport->new->create('food'); print "$report_xml\n";
Aslo the definitions in Moose.pm look like this:
sub super { # This check avoids a recursion loop - see # t/bugs/super_recursion.t return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller(); return unless $SUPER_BODY; $SUPER_BODY->(@SUPER_ARGS); } sub inner { my $pkg = caller(); our ( %INNER_BODY, %INNER_ARGS ); if ( my $body = $INNER_BODY{$pkg} ) { my @args = @{ $INNER_ARGS{$pkg} }; local $INNER_ARGS{$pkg}; local $INNER_BODY{$pkg}; return $body->(@args); } else { return; } }


Comment on Re: You cannot pass args when calling inner() in Moose?
Select or Download Code
Re^2: You cannot pass args when calling inner() in Moose?
by stvn (Monsignor) on Jul 22, 2011 at 02:23 UTC

    This is not actually working, it only appears to work because you are passing a value from @_ into inner(), which it already gets passed anyway. inner() does not accept arguments, same as super().

    -stvn
      Fair enough, thanks for clarifying that.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://915928]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2015-07-03 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (56 votes), past polls