Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

'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?

Thanks!

Comment on 'base' versus @ISA, why?
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 Your Mother (Canon) 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 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.
      Sometimes.

      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 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? (too much)
by tye (Cardinal) on Jul 21, 2007 at 21:31 UTC

    I stopped using base.pm 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 base.pm 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.

      So abandon core modules when become crap?

        A core module, in your words, "becomes crap" and your complaint is with the people who have the good sense to stop using it?1

        If you don't like it, then fix the module so it no longer qualifies as "crap", in your words. Have the appropriate amount of fun.

        Not that I'll be using it after you fix it anyway. Too many "crap" (in your words) versions still in circulation so it isn't worth the risk for the sake of saving one line of code.

        - tye        

        1 I can't help but be reminded of Module::Build, somehow.

Re: 'base' versus @ISA, why?
by creamygoodness (Curate) on Jul 24, 2007 at 14:56 UTC

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

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

    Because that caused base.pm'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 base.pm.

    base.pm is a good idea, but the implementation is problematic.

    --
    Marvin Humphrey
    Rectangular Research ― http://www.rectangular.com
      I ran into base.pm's flakiness just yesterday

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

Re: 'base' versus @ISA, why?
by schwern (Scribe) on Jul 30, 2007 at 21:18 UTC

    Thank you all for your bug reports regarding base.pm 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 base.pm 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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2014-12-19 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (85 votes), past polls