Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Breaking Tie::Hash into three modules

by Corion (Patriarch)
on Sep 09, 2018 at 07:05 UTC ( [id://1221966]=note: print w/replies, xml ) Need Help??


in reply to Breaking Tie::Hash into three modules

Not to detract from your excellent point, parent allows for (and documents) this case:

package MyHash; use Tie::Hash; use parent -norequire, 'Tie::StdHash';

But the real fix is to split the modules up into separate files.

Replies are listed 'Best First'.
Re^2: Breaking Tie::Hash into three modules
by afoken (Chancellor) on Sep 09, 2018 at 09:50 UTC

    Not to detract from your excellent point, parent allows for (and documents) this case:

    package MyHash; use Tie::Hash; use parent -norequire, 'Tie::StdHash';

    I understand that use parent -norequire, 'Some::Class'; can be helpful, but it requires even more typing than our @ISA=('Some::Class');. I've considered for a few seconds if parent could fix what Tie::Hash broke, without forcing me to write more code.

    Adding a few special cases for core modules like Tie::StdHash that exist in files where they should not be. A simple hash mapping broken classes to their containing files ({ 'Tie::StdHash' => 'Tie::Hash', 'Tie::ExtraHash' => 'Tie::Hash', ... }), plus a few lines of code to use that hash. Perhaps only if require failed to load the base class.

    It would have solved the problem that use parent 'Tie::StdHash'; does not work out of the box. But the same would have to be added to base, and to every other module that manipulates @ISA for other modules. And it would require updating the workaround hash from time to time, whenever someone blindly copies the Tie::Hash anti-pattern.

    Another way could have been adding a way to load a class and inherit from a different class to parent, eleminating the need to manually load the file containing the base class. Something like use parent 'Tie::StdHash', -from => 'Tie::Hash'; or use parent { 'Tie::StdHash' => 'Tie::Hash' };.

    But again, why should parent fix what is wrong in other modules?

    After all, parent's history is quite clear:

    This module was forked from base to remove the cruft that had accumulated in it.

    So, after about three seconds, I discarded that idea and did not write about it in the meditation.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1221966]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-26 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found