Barely Used Perl Untapped resources of the perl core libraries #19

Example 1

package Debug;

use Attribute::Handlers;
use Data::Dumper;

our @monitoring;

sub Monitored : ATTR(SCALAR) {
    my ( $package, $symbol, $referent, $attr, $data, $phase ) = @_;

    push @monitoring, $referent;
}

sub report {

    foreach my $var (@monitoring) {

        print Dumper ${$var};
    }
}

package main;

my Debug $test1 : Monitored = "test1";
my Debug $test2 : Monitored = "test2";

Debug->report;
$test1 = ['Houston'];
Debug->report;
$test2 = {'pm' => 1};
Debug->report;
continued...
Copyright © 2007 Robert Boone