first pass at testing
Matt S Trout [Fri, 4 Dec 2009 13:57:58 +0000 (13:57 +0000)]
t/lib/One.pm [new file with mode: 0644]
t/one.t [new file with mode: 0644]

diff --git a/t/lib/One.pm b/t/lib/One.pm
new file mode 100644 (file)
index 0000000..519e901
--- /dev/null
@@ -0,0 +1,11 @@
+package One;
+
+use Moose;
+
+my $called_foo = 0;
+
+sub get_called_foo { $called_foo }
+
+has foo => (is => 'rw', required => 1, trigger => sub { $called_foo++ });
+
+1;
diff --git a/t/one.t b/t/one.t
new file mode 100644 (file)
index 0000000..eddb112
--- /dev/null
+++ b/t/one.t
@@ -0,0 +1,54 @@
+use strict;
+use warnings FATAL => 'all';
+use aliased 'MooseX::Antlers::EvalTracker';
+use aliased 'MooseX::Antlers::RefTracker';
+use aliased 'MooseX::Antlers::RefFilter';
+use B qw(perlstring);
+use lib 't/lib';
+use Test::More;
+
+my %attr_refs;
+my %attr_methods;
+
+{
+  require Moose;
+  my $orig = Moose->can('import');
+  no warnings 'redefine';
+  local *Moose::import = sub {
+    my $targ = caller;
+    Moose->$orig({ into => $targ });
+    my $has = $targ->can('has');
+    {
+      no strict 'refs';
+      *{"${targ}::has"} = sub {
+        $attr_refs{$_[0]} = RefTracker->trace_refs(
+          '$attributes{'.perlstring($_[0]).'}'
+          => \@_
+        );
+        my $et = EvalTracker->new->enable;
+        $has->(@_);
+        $attr_methods{$_[0]} = $et->recorded_coderefs;
+      };
+    }
+  };
+  require One;
+}
+
+ok(One->can('foo'), 'foo accessor installed');
+
+use Data::Dump::Streamer;
+
+my $orig_foo_src = Dump(One->can('foo'));
+
+# write test_class method that checks method including call
+# Class::Unload One
+# build compiled source
+# eval compiled source
+# run test_class after that as well as before unload
+
+use Data::Dumper::Concise;
+
+#warn Dumper \%attr_refs;
+#warn Dumper \%attr_methods;
+
+done_testing;