views:

58

answers:

1

Is it possible to pass variables between multiple calls to the around MethodModier? example (that doesn't work but hopefully conveys what I want to do)

sub mysub { ... };

around 'mysub' => sub {
   my $orig = shift;
   my $self = shift;

   my $value = get_value;

   $self->orig(@_);
};

around 'mysub' => sub {
   my $orig = shift;
   my $self = shift;
   my $value = shift;

   my $output
       = "sometext $value"
       . $self->orig(@_);
       . 'someothertext $value'
       ;
};

I'd eventually like to have these 'arounds' placed in pluggable traits, where I won't really know which ones are loaded beforehand but the final output will be neatly formatted.

It's possible that I'm thinking about this completely wrong, so other suggestions welcome.

A: 

What you are trying to do don't have logic.

"An around modifier receives the original method as its first argument, then the object, and finally any arguments passed to the method."

http://search.cpan.org/~drolsky/Moose-1.09/lib/Moose/Manual/MethodModifiers.pod#BEFORE,_AFTER,_AND_AROUND

Mantovani