jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I think the best way to make my problem visible is with an example:
# main use base qw(A) ; &test() ; package A ; sub test { }
Well, this doesn't work. It works when I call test like:A::test(), but in that case I can replace
use base qw(A) ; to use A ;
So I assume package A has to export its subs, right ?
But in that case I can as well use: use A;.....
Can someone help me out here with how (and when) to use the base class?

Thanks
Luca

Replies are listed 'Best First'.
Re: 'use base' issue
by adrianh (Chancellor) on Mar 08, 2006 at 11:00 UTC
    Can someone help me out here with how (and when) to use the base class?

    base is a convenient shortcut for using a module and setting @ISA. You'll only use it in OO code - not for exporting things. base does not call a modules import() method - so nothing will ever be exported into another package by the normal mechanisms.

Re: 'use base' issue
by davorg (Chancellor) on Mar 08, 2006 at 11:04 UTC

    See the docs for base. It's used for setting the @ISA variable at the same time as loading a module. It would be very rare to find a use for it outside of OO code.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Depending even on the kind of OO you're doing. If using the Object::InsideOut CPAN module you actually don't have to do a 'use base'!

      --
      if ( 1 ) { $postman->ring() for (1..2); }
Re: 'use base' issue
by jeanluca (Deacon) on Mar 08, 2006 at 11:11 UTC
    Oooooh, I think I missed the OO part!!

    Thanks