Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Breaking Tie::Hash into three modules

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


in reply to Breaking Tie::Hash into three modules

More mess

Tie::Array and Tie::Scalar also place Tie::StdArray and Tie::StdScalar in the wrong files. Tie::Scalar also copies the useless new() method from Tie::Hash, including the warnings generated by the real constructor (TIESCALAR() / TIEHASH()).

Tie::Array does not. It does not even implement a TIEARRAY() constructor. I think this is the cleanest solution. If inheriting classes do not implement TIEARRAY(), perl will automatically complain, no code required at all.

Tie::Array implements a dummy DESTROY() method. I don't think it is strictly needed, but it should not hurt.

Tie::Handle does not embed Tie::StdHandle. It was moved out into Tie/StdHandle.pm in 2007 and replaced by a backwards-compatible use Tie::StdHandle;. But it also copies the useless new() method.

More patches

I've written two more patches, that split out the Tie::Std* classes, add strict and warnings, and use parent instead of require and assigning to @ISA.

Tie::Array

Note: Tie::StdArray does not inherit from Tie::Array, because it would inherit only the empty methods EXTEND() and DESTROY(). Instead, it implements its own empty EXTEND() and DESTROY() methods.

Based on https://perl5.git.perl.org/perl.git/blob/83aebc99b27428f0566bab5ded4d1df2167a9d4a:/lib/Tie/Array.pm:

Tie::Scalar

Note: The new Tie::StdScalar does not have a new() method at all. It is not needed, for the same reasons as explained in Re: Breaking Tie::Hash into three modules for Tie::StdHash. It also does not inherit from Tie::Scalar, because it would reimplement all methods (except for new()).

Based on https://perl5.git.perl.org/perl.git/blob/2515a12cf493baaa211da7524a276dd30695ca29:/lib/Tie/Scalar.pm:

Tie::Handle

No patch. I can use parent 'Tie::StdHandle';, so I don't really need to patch here. The synopsis in Tie::StdHandle is wrong (copied from Tie::Handle), but it is quite obvious that only the class name has to be changed to Tie::StdHandle.

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-25 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found