http://www.perlmonks.org?node_id=915928


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; } }

Replies are listed 'Best First'.
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.