summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-04-10 02:18:21 -0500
committerdoy <doy@tozt.net>2009-04-10 02:18:21 -0500
commitf51bf4fadf61e71c669a48ee46380661e9ee2a95 (patch)
tree9cbdd66a42db9ea579d84b68722ce4ca6c7b8318 /t
parent905935092f4be848a98e186a8b7009e220365d9b (diff)
downloadmoosex-nonmoose-f51bf4fadf61e71c669a48ee46380661e9ee2a95.tar.gz
moosex-nonmoose-f51bf4fadf61e71c669a48ee46380661e9ee2a95.zip
add tests for BUILD
Diffstat (limited to 't')
-rw-r--r--t/020-BUILD.t57
1 files changed, 57 insertions, 0 deletions
diff --git a/t/020-BUILD.t b/t/020-BUILD.t
new file mode 100644
index 0000000..e2627f8
--- /dev/null
+++ b/t/020-BUILD.t
@@ -0,0 +1,57 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+package Foo;
+
+sub new {
+ my $class = shift;
+ bless { foo => 'FOO' }, $class;
+}
+
+package Foo::Moose;
+use Moose;
+use MooseX::NonMoose;
+extends_nonmoose 'Foo';
+
+has class => (
+ is => 'rw',
+);
+
+has accum => (
+ is => 'rw',
+ isa => 'Str',
+ default => '',
+);
+
+sub BUILD {
+ my $self = shift;
+ $self->class(ref $self);
+ $self->accum($self->accum . 'a');
+}
+
+package Foo::Moose::Sub;
+use Moose;
+use MooseX::NonMoose;
+extends_nonmoose 'Foo::Moose';
+
+has bar => (
+ is => 'rw',
+);
+
+sub BUILD {
+ my $self = shift;
+ $self->bar('BAR');
+ $self->accum($self->accum . 'b');
+}
+
+package main;
+my $foo_moose = Foo::Moose->new;
+is $foo_moose->class, 'Foo::Moose', 'BUILD method called properly';
+is $foo_moose->accum, 'a', 'BUILD method called properly';
+
+my $foo_moose_sub = Foo::Moose::Sub->new;
+is $foo_moose_sub->class, 'Foo::Moose::Sub', 'parent BUILD method called';
+is $foo_moose_sub->bar, 'BAR', 'child BUILD method called';
+is $foo_moose_sub->accum, 'ab', 'BUILD methods called in the correct order';