http://qs321.pair.com?node_id=277391


in reply to Re^2: USE or Require?
in thread USE or Require?

Why on earth would you want to export new in OO code

I struggled with this one for a while myself, wondering what the idea might be, and I have come to a hypothesis, however shaky. :-) If we want to use a common class framework amongst many classes but dont want them to have a common ISA ancestor then we might make a module like

package ObjectPrototype; use base qw/Exporter/; @EXPORT=qw(new); sub new { my $class=shift; bless {@_},$class }

so now we can say

package Foo; use ObjectPrototype; package Bar; use ObjectPrototype;

without establishing an ISA relationship between any of the module/classes involved.

I admit however that the only reason I could think that this would be useful is if you were doing some funky by hand @ISA tree walking in your code. Having only done this once myself I dont see it being needed much. Although now the thought has come to me... :-)


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

Replies are listed 'Best First'.
Re^4: USE or Require?
by adrianh (Chancellor) on Jul 24, 2003 at 09:01 UTC

    I can't see how it would be very useful since none of the other methods in ObjectPrototype would be available to Foo and Bar :-)

      Well you could have a grab bag of useful methods and approaches all in a single module, and mix and pick as you like. Wheras if you did it via ISA its all or none.


      ---
      demerphq

      <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...