Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

'base' versus @ISA, why?

by rvosa (Curate)
on Jul 21, 2007 at 16:16 UTC ( #628000=perlquestion: print w/replies, xml ) Need Help??

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

Dear monks,

if you're not using 'fields', what's the advantage of using 'base' (if any)? I understand it sets inheritance during compile time, but what does that give me?


Replies are listed 'Best First'.
Re: 'base' versus @ISA, why? (too much)
by tye (Sage) on Jul 21, 2007 at 21:31 UTC

    I stopped using when it got too much featuritis and started trying to guess whether require was needed or not and started guessing wrong (thus silently deciding to not require the parent class so that your code breaks in a rather mysterious way).

    - tye        

      My thoughts exactly. I don't know and I don't WANT to know when thinks it should load a module, and when it thinks it should ignore a require error. On significantly complex systems, setting @ISA and use()ing module "by hand" makes things clearer. Maybe not easier, but clearer none the less.

      Update: I still do use base for simple modules. But I do regularly run into situations where it just doesn't work right.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: 'base' versus @ISA, why?
by schwern (Scribe) on Jul 30, 2007 at 21:18 UTC

    Thank you all for your bug reports regarding which came out of this discussion. I'm very happy that you all took the time to inform the authors and maintainers of this module about your issues. I'm glad you thought to report the bug on RT and made use of the handy email interface so the author can easily track it for consideration later, should they be busy. Or even emailed the current maintainer. Though the documentation is sparse, I'm tickled to have received a patch to add a "how to report a bug" section from all you people who know better.

    I particularly enjoyed the well written test cases which came with your patch. Although not necessary it makes identifying and debugging your problems a pleasure for the overworked author to fix your problem for free. Those who included working and well-formated patches, while not necessary at all to report a bug, were a nice bonus and a joy to apply. I'm pleased to see you're all contributing to Open Source and your concerns back to the people who can do something about it rather than just complaining to each other and the wind in general. Thank you for realizing that CPAN authors do not have the time to troll perlmonks for bugs about their modules. Thank you for making use of the centralized bug tracker which many people labor to keep running and useful for free. It helps immensely, both the author and your odds of getting a fix, to push the bug report to the author.

    Bitching is not doing.

      ++ point taken.
Re: 'base' versus @ISA, why?
by Your Mother (Archbishop) on Jul 21, 2007 at 17:49 UTC

    As I understand it, they aren't quite equivalent. From the docs: Allows you to both load one or more modules, while setting up inheritance from those modules at the same time. Roughly similar in effect to

    package Baz; BEGIN { require Foo; require Bar; push @ISA, qw(Foo Bar); }
Re: 'base' versus @ISA, why?
by diotalevi (Canon) on Jul 21, 2007 at 17:13 UTC

    Operationally, it's the same thing (minus fields). In human language terms, a declaration is purported to be clearer than messing with assignments.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: 'base' versus @ISA, why?
by adrianh (Chancellor) on Jul 21, 2007 at 20:36 UTC

    I prefer base because:

    • Less typing
    • Expresses my intent better
    • Works equally well for inline-packages and external modules - so I don't have to tweak code when I switch between the two.
Re: 'base' versus @ISA, why?
by perrin (Chancellor) on Jul 21, 2007 at 19:20 UTC
    It documents your intent a bit better and it automatically loads the parent module.
      ... and it automatically loads the parent module.

      base is a pretty unreliable module, in my experience, and it must be related to the heuristic method it uses to determine whether a module file needs to be loaded, or not. Sometimes, it guesses wrong.

      update Apparently tye has had similar experiences.

        Looking at the source, I don't see it doing anything except checking if the module is already in your @ISA. That seems pretty sane to me.
Re: 'base' versus @ISA, why?
by creamygoodness (Curate) on Jul 24, 2007 at 14:56 UTC

    I ran into's flakiness just yesterday after sprinkling in the following debug line:

    warn "RDBO version: $Rose::DB::Object::VERSION;"

    Because that caused's dubious heuristic to indicate that there was no need to require Rose::DB::Object I saw an error message along the lines of...

    Can't locate object method "mk_ro_accessors" via package "Foo" at basebug.plx line 11.

    The workaround:

    END { no strict; warn "RDBO version: " . ${ 'Rose::DB::' . 'Object::VERSION' }; }

    The $Foo::VERSION scalar doesn't have to be assigned to; its mere presence in the code as a package global gives it a stash entry and an undefined value. That's apparently enough for is a good idea, but the implementation is problematic.

    Marvin Humphrey
    Rectangular Research ―
      I ran into's flakiness just yesterday

      Which version of Perl? (and did you submit a bug report :-)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://628000]
Approved by Arunbear
Front-paged by grinder
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2022-12-07 04:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found