Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

"Method is not in the class but it is there!"

by shak380 (Novice)
on Sep 05, 2011 at 07:02 UTC ( [id://924144]=perlquestion: print w/replies, xml ) Need Help??

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

The application I currently work on has a class named, CC2::Schema::BirthdayCardList. and there is an object of it which calls a method 'add_to_birthday_cards', but I cant see any so named method or any AUTOLOADs in either the same class or any parent classes of it. So I wonder where this method is located and how it works. I tried to find it with, Class::ISA and the output was as below :
perl -I ~/lib/ -MCC2::Schema::BirthdayCardList -MClass::ISA -le 'for ( +Class::ISA::super_path( "CC2::Schema::BirthdayCardList" )) { print "\ +$_ is : $_"; print "I have the method, add_to_birthday_cards\n" if $_ +->can("add_to_birthday_cards") }'
and the output was as follows :
$_ is : Local::CMSDBIx $_ is : DBIx::Class::InflateColumn::DateTime $_ is : DBIx::Class::InflateColumn $_ is : DBIx::Class::Row $_ is : DBIx::Class::Core $_ is : DBIx::Class::Relationship $_ is : DBIx::Class::Relationship::Helpers $_ is : DBIx::Class::Relationship::HasMany $_ is : DBIx::Class::Relationship::HasOne $_ is : DBIx::Class::Relationship::BelongsTo $_ is : DBIx::Class::Relationship::ManyToMany $_ is : DBIx::Class::Relationship::Accessor $_ is : DBIx::Class::Relationship::CascadeActions $_ is : DBIx::Class::Relationship::ProxyMethods $_ is : DBIx::Class::Relationship::Base $_ is : DBIx::Class::PK::Auto $_ is : DBIx::Class::PK $_ is : DBIx::Class::ResultSourceProxy::Table $_ is : DBIx::Class::ResultSourceProxy $_ is : DBIx::Class $_ is : DBIx::Class::Componentised $_ is : Class::C3::Componentised $_ is : Class::Accessor::Grouped
That is none of them have a so called method. However if I run this :
perl -I ~/lib/ -MCC2::Schema::BirthdayCardList -le 'print "Yes.....\n" + if CC2::Schema::BirthdayCardList->can("add_to_birthday_cards")'
it prints "Yes.....". So what is magical here ?

Replies are listed 'Best First'.
Re: "Method is not in the class but it is there!"
by chrestomanci (Priest) on Sep 05, 2011 at 09:42 UTC

    I see that you have asked the same question on LinkedIn

    No one here at the monastery will object to you seeking opinions elsewhere. We are not perfect and for some questions there are likely to be wise persons on other forums with better answers, but when you do ask a question in multiple places it is courteous to say so, and to provide links, so that we can see what others have said in those other forums, so that we may learn from them, and avoid repeating the same answer.

      Yes, I understand. I was waiting for a correct answer and I have done it! so no worries!
Re: "Method is not in the class but it is there!"
by Anonymous Monk on Sep 05, 2011 at 07:19 UTC

    Probably nothing

    use Data::Dump::Streamer; print Dump( CC2::Schema::BirthdayCardList->can("add_to_birthday_cards") );
      I believe there is something, otherwise how does the code work ? btw, I executed your code and it didn't produce anything. Anymore ideas from anyone ?

        That is not possible :) it should produce something

        use Data::Dump::Streamer; print Dump( Data::Dump::Streamer->can('VERSION') ); __END__ $CODE1 = \&UNIVERSAL::VERSION;
Re: "Method is not in the class but it is there!"
by JavaFan (Canon) on Sep 05, 2011 at 08:15 UTC
    Do note, as the output shows, that Class::ISA::super_path does not return the package it's called with (unless there's a loop in the inheritance structure). So, if &CC2::Schema::BirthdayCardList::add_to_birthday_cards exists, you get the behaviour you are seeing.

    Alternatively, someone has put it in UNIVERSAL, which also isn't returned by super_path.

      >> "if &CC2::Schema::BirthdayCardList::add_to_birthday_cards exists, you get the behaviour you are seeing" Yes, that is obvious, but as I mentioned there is no such method or a single word 'add_to_birthday_cards' in the module, CC2::Schema::BirthdayCardList. Also, it is not in UNIVERSAL, please see this :
      perl -I ~/cc-tmpl/lib/ -MUNIVERSAL -le 'print "Yes.....\n" if UNIVERSA +L->can("add_to_birthday_cards")'
      doesn't print "Yes.....". Also,
      grep 'add_to_birthday_cards' /usr/lib/perl5/5.8.8/UNIVERSAL.pm -rli
      outputs nothing.
        Note that Perl supports creation of methods with dynamic names at run time and compile time, so a grep not showing a result suggest that this might be the case.
        If you can't find it at all, and if the method uses variables, pass in a tied variable that dumps a stack trace on a FETCH. That should give you some line numbers to work with (or an indication the method was evalled into existence).
        Um, UNIVERSAL.pm is a core module, nobody edits UNIVERSAL.pm, but modules/programs, might at runtime, despite it being a bad practice, add symbols to UNIVERSAL namespace
Re: "Method is not in the class but it is there!"
by moritz (Cardinal) on Sep 05, 2011 at 10:13 UTC
Re: "Method is not in the class but it is there!"
by shak380 (Novice) on Sep 05, 2011 at 10:24 UTC
    Hi guys, Thank you all for your valuable suggestions and helping me out. Anyway, I have got a seemingly right answer from linkedin(Perl group). I will confirm it and will post the result later. Anyways, here is the link : <link>http://www.linkedin.com/groupItem?view=&gid=106254&type=member&item=69158748&qid=d1a40232-965a-4706-88f1-6e43e50a965a&trk=group_most_popular-0-b-ttl&goback=%2Egde_106254_member_69158748%2Egmp_106254</link>
      Yes, that answer is correct indeed! I have tested and confirmed it.
        Well, what is it?
        A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://924144]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-24 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found