[Israel.pm] OO Perl and Exporter

Issac Goldstand margol at beamartyr.net
Tue Dec 28 05:00:44 PST 2004

You beat me to the asnwer.
Class/instance methods are whatever you make of them.  The only difference 
AFAIK is that in the example of $object->method(), you'll get $object (the 
variable, not just the bless()ed name) passed, whereas with Class->method(), 
you'll only get the string "Class" passed.

So it's certainly fair to wrap long variables in one big hash, and make 
accessor methods to it...  But it doesn't really "gain" you anything - since 
you could just as easily have done:
  my *localref=*Some::Long::Annoying::Class::Name::would_be_bloessed_ref

(After thinking a bit about that, that's probably not true, since you could 
have a cute set of methods like :
sub var1 {
    shift; # Ignore the class
    if ($_[0]) { $my_locally_namespaced_var1=$_[0];}
    return $my_locally_namespaced_var1;

Having wrote that, I assume that's what Offer meant)

The origianl point still holds, though, in that the class method/instance 
method isn't important...  And then, no you shouldn't need to use exporter - 
I generally don't in my OO modules.


----- Original Message ----- 
From: "Offer Kaye" <offer.kaye at gmail.com>
To: "Perl in Israel" <perl at perl.org.il>
Sent: Tuesday, December 28, 2004 2:34 PM
Subject: Re: [Israel.pm] OO Perl and Exporter

> On Tue, 28 Dec 2004 12:37:35 +0200 (IST), Shlomo Yona wrote:
>> You're right about instance methods, but what about static
>> methods (methods that belong to the class and not to a
>> particular instance of it)?
> After a bit of searching, I found "perldoc perltooc". You can read
> yourself, but the important bit for this discussion is this, I think:
>       You should allow access to class attributes through either the class
>       name or any object of that class.  If we assume that $an_object is 
> of
>       type Some_Class, and the &Some_Class::population_count method 
> accesses
>       class attributes, then these two invocations should both be 
> possible,
>       and almost certainly equivalent.
>           Some_Class->population_count()
>           $an_object->population_count()
> In other words, continuing your original example, if f properly
> written, the user should be able to write both:
> My::Module::With::Its::Long::Name::method();
> and
> $object->method();
> Because it shouldn't matter to the user that "method()" is actually a
> class method. Bottom line, in Perl, there's really no distinction -
> both object and class method are just subroutines.
> So getting back to _my_ original question - is there any valid reason
> to use Exporter in a pure, OO module?
> -- 
> Offer Kaye
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl

More information about the Perl mailing list