| 1 |
#!/opt/perl/bin/perl |
| 2 |
# just a small example script for testing whether memory might be leaked. |
| 3 |
|
| 4 |
package test; |
| 5 |
|
| 6 |
use Object::Event; |
| 7 |
|
| 8 |
our @ISA = qw/Object::Event/; |
| 9 |
|
| 10 |
sub new { |
| 11 |
my $c = shift; |
| 12 |
my $self = $c->SUPER::new (@_); |
| 13 |
|
| 14 |
# register on the 'up' event and then call the 'down' event |
| 15 |
$self->reg_cb (up => sub { $self->event ('down'); }); |
| 16 |
|
| 17 |
$self |
| 18 |
} |
| 19 |
|
| 20 |
sub up { |
| 21 |
my ($self) = @_; |
| 22 |
|
| 23 |
$self->event ('up'); # genereate an internal up event |
| 24 |
} |
| 25 |
|
| 26 |
package main; |
| 27 |
|
| 28 |
my $t = test->new; |
| 29 |
|
| 30 |
my $cnt = 0; |
| 31 |
$t->reg_cb ( # reg_cb registers on a set of specific events |
| 32 |
down => sub { |
| 33 |
my ($t) = @_; |
| 34 |
$cnt++; |
| 35 |
} |
| 36 |
); |
| 37 |
|
| 38 |
for (1..1000000) { |
| 39 |
$t->up; # test will emit the 'down' even we registered upon above |
| 40 |
if ($cnt % 1000) { print "$cnt\n" } |
| 41 |
} |