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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|