Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

'use subs' causes method to vanish

by gnosti (Friar)
on Feb 05, 2009 at 20:34 UTC ( #741684=perlquestion: print w/ replies, xml ) Need Help??
gnosti has asked for the wisdom of the Perl Monks concerning the following question:

Hello August Monks and Monkesses!

I've got an app with a subroutine, init_gui(), that is called through an object:

$ui->init_gui

When I add the line:

use subs 'init_gui';

to the Graphical package where init_gui() is defined, my app dies with undefined subroutine &...Graphical::init_gui called in line 895.

A test using an identical object model does not exhibit this behavior, nor does 'use subs' cause every method to fail.

What parts of perl or of my app, should I be examining to better understand what is going on? AFAIK there is no source filtering where I can lay the blame.

Thanks for reading.

Comment on 'use subs' causes method to vanish
Select or Download Code
Re: 'use subs' causes method to vanish
by linuxer (Deacon) on Feb 05, 2009 at 20:42 UTC

    Having read the perldoc subs I wonder, if it is intented for usage in OO style. Though I cannot explain what happens internally.

Re: 'use subs' causes method to vanish
by zwon (Monsignor) on Feb 05, 2009 at 20:43 UTC

    use subs rewrites existing symbols. Place use subs before init_gui definition. There's no sense to use subs after function is declared.

    Update: BTW, I don't think you should use subs at all in this application.

      You're right, I don't need (and from this result won't be using) use subs for an object method. I only encountered this because I used a script to use subs for all subs, to be able to begin to get rid of parentheses for non-object subs.

      I can sort out the methods from the subs and solve the problem, and I'd like to understand perl internals better, too. Hence this posting.

        I only encountered this because I used a script to use subs for all subs, to be able to begin to get rid of parentheses for non-object subs.

        As you've seen, that's a bad idea. If you're rigorous about the order in which Perl compiles your code, you can get away with it... but I like to avoid code which relies on a well-defined order of appearance in the compilation process, as it seems fragile.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2014-07-26 01:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls