On Tue, Aug 11, 2009 at 02:14, Jenn G.<practicalp...@gmail.com> wrote:
> Hello,
>
> When I create a package, and call its methods by both object way and
> function (exported) way, how to avoid the conflict in arguments
> passing?
snip

Short answer: don't do that.

Medium answer:

Mixing procedural and OO style in the same library leads to confusion
and there is little reason to support the the procedural style.  Just
use the OO style.

How to actually do it:

Use Scalar::Util::blessed and and ->isa() to determine if the first
argument is an object that can be calling this method:

use Scalar::Util qw/blessed/;

sub foo {
    if (blessed $_[0] and $_[0]->isa(__PACKAGE__)) {
        #being called as a method
    } else {
        #being called procedural style
    }
}

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to