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

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->().

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2018-05-21 01:42 GMT
Find Nodes?
    Voting Booth?