Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^8: Can't call method "otherwise" without a package or object reference at

by rpelak (Sexton)
on Oct 06, 2010 at 17:01 UTC ( #863834=note: print w/ replies, xml ) Need Help??


in reply to Re^7: Can't call method "otherwise" without a package or object reference at
in thread Can't call method "otherwise" without a package or object reference at

I'll admit I haven't run the deparse before... so I can't read it very well (at least for this try catch stuff... But For the code that was added simply to prove that otherwise is defined.

do { (my($k) = 2); 'sysAssert'->throw('test assert') }->try('err'->catch(do { (my($ex) = @_); print("caught by with\n"); dPrt('warn', " with $ex") }->with(do { (my($ex) = @_); print("caught by otherwise \n"); dPrt('warn', "OTHERWISE:$ex") }->otherwise)));
For the original offending code that generates the error about can't call method "otherwise"... that I am trying to fix...
if (($pbOnDStarMachine == 1)) { (my($sComm) = "sudo dchown nhmgenda '$$this{'sFullPath'}'"); do { libs::exec("$sComm") }->try('err'->catch(do { (my($ex) = @_); dPrt('warn', "$ex") }->with(do { (my($ex) = @_); dPrt('warn', "OTHERWISE:$ex") }->otherwise))); return(''); }


Comment on Re^8: Can't call method "otherwise" without a package or object reference at
Select or Download Code
Re^9: Can't call method "otherwise" without a package or object reference at
by ikegami (Pope) on Oct 06, 2010 at 23:08 UTC

    No surprise. It just confirms that Perl thinks you have indirect method calls where you didn't mean use such. In both cases.

    Could you place the following just before your sub and provide the output:

    BEGIN { no strict 'refs'; no warnings 'uninitialized'; printf("package %s\n", __PACKAGE__); for (qw( try catch with otherwise err )) { printf("%s: exists:%s defined:%s prototype:%s\n", $_, exists(&{$_}) || 0, defined(&{$_}) || 0, prototype($_), ); } }

    Update: Removed bad slashes.

      Well it seems I have stumbled onto a fix...
      Previously the Error.pm was pulled in by one of my modules (myExceptions), which was pulled in by another module, that was pulled into the one running the code. Apparently that we too many levels or something, somehow (since it works in some cases not in others). But when I directly pulled in myExceptions in the module doing the code, it started working.
      All said and done, this is better coding this way anyway...
      So thanks for all the help... the otherwise clause does indeed work the way we thought... and all is well (well the script still doesn't work, but this isn't the reason why... :) )

        Apparently that we too many levels or something

        No, there's no reason to believe the module wasn't being loaded. You simply never imported the functions into the current package.

        Elaborating on the above post:
        { package PkgA; # Loads the module if it's not loaded, and import "foo". use SomeModule qw( foo ); foo(); # ok } { package PkgB; # Loads the module if it's not loaded, importing nothing. use SomeModule qw( ); foo(); # Error. No such function in PkgB SomeModule::foo(); # ok } { package PkgC; # The module might be loaded, but nothing is imported from it. foo(); # No such function in PkgC }

        You package is like PkgC.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-08-21 05:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls