shemp has asked for the wisdom of the Perl Monks concerning the following question:

I am creating an AUTOLOAD for a class im writing. There is a hashref of Class::Struct's as object data. Im using autoload to pass calls to the proper Class::Struct. For example, here is a stripped down version of what im trying to do
use Class::Struct; struct Blah => { 'data_1' => $, 'data_2' => $, }; if ( Blah::can('data_1') ) { print "Blah can data_1\n"; } else { print "Blah can NOT data_1\n"; }
This does not work, i get the errorUndefined subroutine &Blah::can called at Blah.pl line 13.
I have never quite figured out all the nuances of can(), I dont know if this is possible, and using Class:Struct, im not sure if a real package is created.

Of course i can check the method trapped by AUTOLOAD to see if its a data element of the struct.

Is any of this possible?
thanks much

Replies are listed 'Best First'.
Re: using can() without an object instance?
by dragonchild (Archbishop) on Jun 29, 2004 at 17:29 UTC
    Try either Blah->can('foo') or UNIVERSAL::can('Blah', 'foo').

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Duh! - i guess my brain is not working today - thanks
      Blah->can('foo');
      is great!