Subject: | PATCH: additional tests |
Attached is a patch with more tests for additional cases:
- self being used by both a parent and child modules
- self being used by two unrelated modules at the same time, to test
both really do have a "private" self object.
All the new tests passed.
And this could go in a separate 'wish' ticket, but I think it would be
great if the name of 'self' could be renamed. This feature would be
'free' if you used Sub::Exporter instead of Exporter::Lite. See:
http://search.cpan.org/dist/Sub-Exporter/lib/Sub/Exporter/Tutorial.pod#Renaming_Your_Imports
Subject: | more_tests.patch |
diff -rN -u self-0.11-old/t/0simple.t self-0.11-new/t/0simple.t
--- self-0.11-old/t/0simple.t 2007-10-28 06:21:27.000000000 -0400
+++ self-0.11-new/t/0simple.t 2007-11-02 13:26:19.000000000 -0400
@@ -1,16 +1,36 @@
use lib 't/lib';
use Counter;
-use Test::More tests => 3;
+use Test::More tests => 9;
-my $o = Counter->new;
-
-is($o->out, 0);
-
-$o->inc;
-
-is($o->out, 1);
-
-$o->set(5);
-
-is($o->out, 5);
+{
+ my $o = Counter->new;
+ is($o->out, 0);
+ $o->inc;
+
+ is($o->out, 1);
+ $o->set(5);
+
+ is($o->out, 5);
+}
+
+{
+ my $o = ChildofCounter->new;
+ is($o->out, 0);
+ $o->inc;
+
+ is($o->out, 1);
+ $o->set(5);
+
+ is($o->out, 5);
+}
+{
+ my $o = SecondCounter->new;
+ is($o->out, 0);
+ $o->inc;
+
+ is($o->out, 1);
+ $o->set(5);
+
+ is($o->out, 5);
+}
diff -rN -u self-0.11-old/t/lib/Counter.pm self-0.11-new/t/lib/Counter.pm
--- self-0.11-old/t/lib/Counter.pm 2007-10-28 06:40:42.000000000 -0400
+++ self-0.11-new/t/lib/Counter.pm 2007-11-02 13:25:38.000000000 -0400
@@ -2,7 +2,32 @@
use warnings;
package Counter;
+use self;
+
+sub new {
+ my $class = shift;
+ return bless {
+ v => 0
+ }, $class;
+}
+
+sub set {
+ my ($v) = args;
+ self->{v} = $v;
+}
+
+sub out {
+ self->{v};
+}
+
+sub inc {
+ self->{v}++;
+}
+
+package ChildofCounter;
+use base 'Counter';
+package SecondCounter;
use self;
sub new {