package Test::Gladiator; use Scalar::Util qw(weaken); use Cwd; use File::Spec; sub new { my $class = shift; my $file = File::Spec->catfile( getcwd(), 'gladiator_output.txt' ); open( my $out, '>', $file ) or die "Cannot create $file: $!"; my $self = { counting => {}, out_h => $out }; return bless $self, $class; } sub DESTROY { my $self = shift; close( $self->{out_h} ) or die $!; } sub show_accounting { my $self = shift; my $out = $self->{out_h}; foreach my $key ( sort( keys( %{ $self->{counting} } ) ) ) { print $out $key, '|', join( '|', @{ $self->{counting}->{$key} } ), "\n" if ( $self->{counting}->{$key}->[1] > $self->{counting}->{$key}->[0] ); } } sub count_leaks { my $self = shift; my $total = 0; foreach my $key ( keys( %{ $self->{counting} } ) ) { my $last = $#{ $self->{counting}->{$key} }; $total++ if ( $self->{counting}->{$key}->[$last] > $self->{counting}->{$key}->[ $last - 1 ] ); } return $total; } sub increment_count { my $self = shift; my $current = shift; weaken($current); foreach my $key ( keys( %{$current} ) ) { if ( exists( $self->{counting}->{$key} ) ) { push( @{ $self->{counting}->{$key} }, $current->{$key} ); } else { $self->{counting}->{$key} = [ $current->{$key} ]; } } } 1;