Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
"be consistent"
 
PerlMonks  

Re: Tieing and Blessing

by McA (Deacon)
on Oct 05, 2012 at 09:34 UTC ( #997418=note: print w/ replies, xml ) Need Help??


in reply to Tieing and Blessing

Hi all

As so often. As soon as I wrote my question in a structured way I had the idea just to try what tobyink answered meanwhile. Thank you for that, tobyink.

I just wanted to present my little code snippet:

use strict; use warnings; use Data::Dumper; use Tie::Hash (); package MyHash; use base 'Tie::StdHash'; sub TIEHASH { my $storage = bless {}, shift; warn "New hash created, stored in $storage.\n"; return $storage; } sub STORE { my $class = shift; warn "In STORE\n"; return $class->SUPER::STORE(@_); } package MyObj; sub new { my $class = shift; my %h; tie %h, 'MyHash'; return bless \%h, $class; } sub do_something { print "In method do_something\n"; } package main; my $g = MyObj->new(); $g->do_something(); $g->{'key'} = 'value'; print Dumper($g), "\n";

UPDATE: As expected, tobyink presented a much fancier code example showing the right way to write test code. A ++ for that.

Best regards
McA


Comment on Re: Tieing and Blessing
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2014-04-24 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls