Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Passing subroutine as argument between packages

by Eliya (Vicar)
on Nov 30, 2011 at 14:26 UTC ( #940869=note: print w/ replies, xml ) Need Help??

in reply to Passing subroutine as argument between packages

Valid usage this function: $FooConfig->important_func, but reference return &PackageName:: before

I'm not sure I understand what your problem is.  As it seems, you appear to have figured out that the correct way to call the method would be $FooConfig->important_func( ... ). So where/when are you getting the &PackageName:: you don't want?

Upon rethinking, maybe you want something like this

my $ref = sub { $FooConfig->important_func( '1' ) };

which would 'bind' the object instance and the method parameter to the coderef, so that you could call it later on as $ref->().

Comment on Re: Passing subroutine as argument between packages
Select or Download Code
Replies are listed 'Best First'.
Re^2: Passing subroutine as argument between packages
by Mateusz (Initiate) on Nov 30, 2011 at 18:13 UTC

    Thank you for you answer,

    I want ask you about one more thing: in this method, how pass eventually arguments for subroutine $FooConfig->important_func?

    I checked $ref()->('a' ), $ref()('a'), $ref->( 'a' ), $ref->()('a'), $ref->()->('a') or like this, and didn't work.


      my $ref = sub { $FooConfig->important_func( '1', @_ ) };

      ... then you can write:

      $ref->( 'more', $args, %here );

      ... though be cautious and understand how the function reference passes its arguments to the inner function.

      Improve your skills with Modern Perl: the free book.

        Simple @_ is solution - now works fine!

        Thanks for very helpfull hints.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2015-11-30 18:13 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (778 votes), past polls