Commits

Shlomi Fish committed b320070

Moved Stacker and Counter to their own packages.

Comments (0)

Files changed (6)

 t/61error.t
 t/80registryleak.t
 t/90threads.t
+t/lib/Collector.pm
+t/lib/Counter.pm
+t/lib/Stacker.pm
 t/lib/TestHelpers.pm
 t/pod.t
 test/relaxng/badschema.rng
     'ABSTRACT'  => 'Interface to Gnome libxml2 xml parsing and DOM library',
     'LICENSE' => 'perl',
     'PREREQ_PM' => {
+        'base' => 0,
         'ExtUtils::MakeMaker' => '6.56',
         'strict' => 0,
         'Test::More' => 0,

t/28new_callbacks_multiple.t

 
 use lib './t/lib';
 
-package Collector;
-
-sub new
-{
-    my $class = shift;
-
-    my $self = bless {}, $class;
-
-    $self->_init(@_);
-
-    return $self;
-}
-
-sub _init
-{
-    my $self = shift;
-    my $args = shift;
-
-    $self->_reset;
-
-    $self->_callback( $args->{gen_cb}->($self->_calc_op_callback()) );
-
-    $self->_init_returned_cb;
-
-    return;
-}
-
-sub _callback
-{
-    my $self = shift;
-
-    if (@_)
-    {
-        $self->{_callback} = shift;
-    }
-
-    return $self->{_callback};
-}
-
-sub _returned_cb
-{
-    my $self = shift;
-
-    if (@_)
-    {
-        $self->{_returned_cb} = shift;
-    }
-
-    return $self->{_returned_cb};
-}
-
-sub _init_returned_cb
-{
-    my $self = shift;
-
-    $self->_returned_cb(
-        sub {
-            return $self->_callback()->(@_);
-        }
-    );
-
-    return;
-}
-
-sub cb
-{
-    return shift->_returned_cb();
-}
-
-package Counter;
-
-our @ISA = qw(Collector);
-
-sub _counter
-{
-    my $self = shift;
-
-    if (@_)
-    {
-        $self->{_counter} = shift;
-    }
-
-    return $self->{_counter};
-}
-
-
-sub _increment
-{
-    my $self = shift;
-
-    $self->_counter($self->_counter + 1);
-
-    return;
-}
-
-sub _reset
-{
-    my $self = shift;
-
-    $self->_counter(0);
-
-    return;
-}
-
-sub _calc_op_callback {
-    my $self = shift;
-
-    return sub {
-        return $self->_increment();
-    };
-}
-
-sub test
-{
-    my ($self, $value, $blurb) = @_;
-
-    local $Test::Builder::Level = $Test::Builder::Level + 1;
-
-    Test::More::is ($self->_counter(), $value, $blurb);
-
-    $self->_reset;
-
-    return;
-}
-
-1;
-
-package Stacker;
-
-use TestHelpers;
-
-our @ISA = qw(Collector);
-
-sub _stack
-{
-    my $self = shift;
-
-    if (@_)
-    {
-        $self->{_stack} = shift;
-    }
-
-    return $self->{_stack};
-}
-
-sub _push
-{
-    my $self = shift;
-    my $item = shift;
-
-    push @{$self->_stack()}, $item;
-
-    return;
-}
-
-sub _reset
-{
-    my $self = shift;
-
-    $self->_stack([]);
-
-    return;
-}
-
-sub _calc_op_callback {
-    my $self = shift;
-
-    return sub {
-        my $item = shift;
-
-        return $self->_push($item);
-    };
-}
-
-sub test
-{
-    my ($self, $value, $blurb) = @_;
-
-    local $Test::Builder::Level = $Test::Builder::Level + 1;
-
-    eq_or_diff ($self->_stack(), $value, $blurb);
-
-    $self->_reset;
-
-    return;
-}
-1;
-
-package main;
+use Counter;
+use Stacker;
 
 # Should be 56
 use Test::More tests => 56;

t/lib/Collector.pm

+package Collector;
+
+use strict;
+use warnings;
+
+sub new
+{
+    my $class = shift;
+
+    my $self = bless {}, $class;
+
+    $self->_init(@_);
+
+    return $self;
+}
+
+sub _init
+{
+    my $self = shift;
+    my $args = shift;
+
+    $self->_reset;
+
+    $self->_callback( $args->{gen_cb}->($self->_calc_op_callback()) );
+
+    $self->_init_returned_cb;
+
+    return;
+}
+
+sub _callback
+{
+    my $self = shift;
+
+    if (@_)
+    {
+        $self->{_callback} = shift;
+    }
+
+    return $self->{_callback};
+}
+
+sub _returned_cb
+{
+    my $self = shift;
+
+    if (@_)
+    {
+        $self->{_returned_cb} = shift;
+    }
+
+    return $self->{_returned_cb};
+}
+
+sub _init_returned_cb
+{
+    my $self = shift;
+
+    $self->_returned_cb(
+        sub {
+            return $self->_callback()->(@_);
+        }
+    );
+
+    return;
+}
+
+sub cb
+{
+    return shift->_returned_cb();
+}
+
+1;
+package Counter;
+
+use strict;
+use warnings;
+
+use base 'Collector';
+
+sub _counter
+{
+    my $self = shift;
+
+    if (@_)
+    {
+        $self->{_counter} = shift;
+    }
+
+    return $self->{_counter};
+}
+
+
+sub _increment
+{
+    my $self = shift;
+
+    $self->_counter($self->_counter + 1);
+
+    return;
+}
+
+sub _reset
+{
+    my $self = shift;
+
+    $self->_counter(0);
+
+    return;
+}
+
+sub _calc_op_callback {
+    my $self = shift;
+
+    return sub {
+        return $self->_increment();
+    };
+}
+
+sub test
+{
+    my ($self, $value, $blurb) = @_;
+
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+    Test::More::is ($self->_counter(), $value, $blurb);
+
+    $self->_reset;
+
+    return;
+}
+
+1;
+package Stacker;
+
+use strict;
+use warnings;
+
+use TestHelpers;
+
+use base 'Collector';
+
+sub _stack
+{
+    my $self = shift;
+
+    if (@_)
+    {
+        $self->{_stack} = shift;
+    }
+
+    return $self->{_stack};
+}
+
+sub _push
+{
+    my $self = shift;
+    my $item = shift;
+
+    push @{$self->_stack()}, $item;
+
+    return;
+}
+
+sub _reset
+{
+    my $self = shift;
+
+    $self->_stack([]);
+
+    return;
+}
+
+sub _calc_op_callback {
+    my $self = shift;
+
+    return sub {
+        my $item = shift;
+
+        return $self->_push($item);
+    };
+}
+
+sub test
+{
+    my ($self, $value, $blurb) = @_;
+
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+    eq_or_diff ($self->_stack(), $value, $blurb);
+
+    $self->_reset;
+
+    return;
+}
+
+1;