Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Breaking Tie::Hash into three modules

by afoken (Chancellor)
on Sep 09, 2018 at 10:16 UTC ( [id://1221971]=note: print w/replies, xml ) Need Help??


in reply to Breaking Tie::Hash into three modules

Tie::StdHash

For the last 16 years, it seems that nobody complained about Tie::StdHash no longer inheriting the useless new() from Tie::Hash. So I am very sure that we can also move that class safely out of Tie/Hash.pm.

Having a fresh look at the code of both Tie::StdHash and Tie::Hash explains why nobody complained:

  • Tie::Hash::TIEHASH() is designed to call new() in an inheriting class, or to be reimplemented by the inheriting class. If the inheriting class implements neither new() nor TIEHASH(), Tie::Hash::TIEHASH() croak()s.
  • (If the inheriting class implements new(), but not TIEHASH(), Tie::Hash::TIEHASH() warns that it calls new() because TIEHASH() is missing. So why even bother to implement new()?)
  • Tie::Hash::new(), which is never called by tie, just calls TIEHASH() of the inheriting class. Implementing new() in an inheriting class does not make any sense at all, because you need a class name, not an object, for tie.
  • Tie::StdHash implements its own TIEHASH(), as expected by Tie::Hash and tie. This prevents new() from being called indirectly from tie().

So, no class inheriting from Tie::StdHash needs a new() implementation.

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://1221971]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-23 22:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found