http://qs1969.pair.com?node_id=628000

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!

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 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.

    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 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.
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.
      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 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 :-)