in reply to $object->UnrelatedPackage::some_subroutine()

Interesting. I was just trying to use that a couple of days ago. It didn't work on the several platforms I tried, though I rarely have 5.8 or later to use anywhere:

$ perl -e "Lie->Pkg::Meth()" Can't locate object method "Meth" via package "Pkg::Meth" at -e line 1 +. $

Notice it tried to look for Pkg::Meth::Meth() not Pkg::Meth().

No, I haven't looked any further. It was easy enough to work around, either as you noted or, better, using can(). And, no, it didn't work with a blessed object any better than it did with a class name.

Update: The two copies of Perl I have handy right now are both 5.6.1 (Zaurus Linux and FreeBSD) and they both have this bug.

- tye        

Replies are listed 'Best First'.
Re^2: $object->UnrelatedPackage::some_subroutine() (not for me)
by Thilosophy (Curate) on Feb 18, 2005 at 06:05 UTC
    Hmm. Your example works for me ( v5.8.1-RC3 built for darwin-thread-multi-2level):
    $ perl -e 'Lie->Pkg::Meth()' Can't locate object method "Meth" via package "Pkg" (perhaps you forgo +t to load "Pkg"?) at -e line 1.

    Is this a new or unstable feature?
    I checked 5.8.1-RC3 (works), 5.8.0 (works), 5.6.1 (works).

    And contrary to what I thought, you do not have to use a blessed reference, a package name is fine as well. It also works with a string scalar:

    $ perl -e '$a = "Lie"; $a->Pkg::Meth()' Can't locate object method "Meth" via package "Pkg" (perhaps you forgo +t to load "Pkg"?) at -e line 1.

    But not with other types of parameters (that cannot qualify as class name or object instance):

    $ perl -e '$a = []; $a->Pkg::Meth()' Can't call method "Pkg::Meth" on unblessed reference at -e line 1. $ perl -e '$a = 123; $a->Pkg::Meth()' Can't call method "Pkg::Meth" without a package or object reference at + -e line 1.
Re^2: $object->UnrelatedPackage::some_subroutine() (not for me)
by itub (Priest) on Feb 18, 2005 at 14:12 UTC
    The error message is wrong (in version 5.6.1), but the feature works perfectly well if you call a method that really exists:
    perl -e 'package Pkg; sub Meth{print "hello\n"} package main; Lie->Pkg +::Meth'
    hello
    

      The root cause was probably my previous misunderstanding at how Apache::DBI and DBI are related. I didn't look at the failure much after producing the above test case because the work-arounds were too easy.

      Thanks.

      - tye