in reply to reference to a subroutine inside a package

There's no parse_tag in test; it inherits that method from gadget.

You could take a reference to it if you had an instance of twig; call can on the instance and assign the results to a scalar variable. Beware that if you invoke the subroutine reference, it hasn't curried the invocant, so you'll have to pass in an appropriate object yourself.

I'm not sure what problem you're trying to solve, but there are various other, more painful ways to accomplish the same thing.

Replies are listed 'Best First'.
Re^2: reference to a subroutine inside a package
by imcsk8 (Pilgrim) on Jun 02, 2004 at 23:46 UTC
    thanks with can i can do the reference, but yes i have to instantiate the class and pass it as an argument (that's not problem, well if you are an OO purist it is)

    what i am trying to do is to load references to subroutines in diferent packages, so i process them with the twig_roots attribute of XML::Twig, in my application i represent an XML tag as a package that inherits the standard behaviour from another (the base class of all xml elements of my application). in here i'm kind of confused because i can't pass parameters to the subroutine i'm referencing, so it this subroutine is a class method (it does not recieve a reference to an instance of the class as the first argument), and i don't know if i should create an instance to the class inside this method (i don't want to do this because i think it is kind of dirty).
    i don't think this approach is very good but i can't think of another one
    thanks


    ignorance, the plague is everywhere
    --guttermouth
      but yes i have to instantiate the class and pass it as an argument (that's not problem, well if you are an OO purist it is)
      why would that be a problem for OO purists?
          $object->$coderef($arg1, $arg2, ...);
      seems to be perfect OO style...

      update: one might think (i thought that too for a while) that only
          $coderef->($object, $arg1, $arg2, ...);
      will work, which, of course, isn't too nice OOP.

        seems to be perfect OO style...

        Because you are used to seeing this. Some OO purists dislike arguments (to methods, not the other kind). They would probably prefer it like this:

                $object->$coderef( $object->$other_coderef_to_access_arg1_through_argn );

        Cheers, Sören