Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Richard Simões
committed
Oct 13, 2011
1 parent
1a30b7b
commit e23505c
Showing
19 changed files
with
746 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package MouseX::NonMoose::Meta::Role::Class; | ||
use Mouse::Role; | ||
use Mouse::Util::MetaRole; | ||
|
||
with 'MouseX::Foreign::Meta::Role::Class'; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package MouseX::NonMoose::Meta::Role::Method::Constructor; | ||
use Mouse::Role; | ||
|
||
around _generate_constructor => sub { | ||
my($next, undef, $meta, $option) = @_; | ||
|
||
# The foreign superlcass must have the new method | ||
my $foreign_buildargs = $meta->name->can('FOREIGNBUILDARGS'); | ||
my $foreign_superclass = $meta->foreign_superclass; | ||
my $super_new = $foreign_superclass->can('new'); | ||
my $needs_buildall = !$foreign_superclass->can('BUILDALL'); | ||
|
||
return sub { | ||
my $class = shift; | ||
my $object = $foreign_buildargs | ||
? $class->$super_new($class->$foreign_buildargs(@_)) | ||
: $class->$super_new( @_ ); | ||
my $args = $class->BUILDARGS(@_); | ||
$object->meta->_initialize_object($object, $args); | ||
$object->BUILDALL($args) if $needs_buildall; | ||
|
||
return $object; | ||
}; | ||
}; | ||
|
||
no Mouse::Role; | ||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package MouseX::NonMoose::Meta::Role::Method::Destructor; | ||
use Mouse::Role; | ||
|
||
around _generate_destructor => sub { | ||
my($next, undef, $meta) = @_; | ||
|
||
my $foreign_superclass = $meta->foreign_superclass; | ||
|
||
my $super_destroy; | ||
if(!$foreign_superclass->can('DEMOLISHALL')){ | ||
$super_destroy = $foreign_superclass->can('DESTROY'); | ||
} | ||
|
||
return sub { | ||
my($self) = @_; | ||
$self->DEMOLISHALL(); | ||
|
||
if(defined $super_destroy) { | ||
$self->$super_destroy(); | ||
} | ||
return; | ||
}; | ||
}; | ||
|
||
no Mouse::Role; | ||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
|
||
package Foo; | ||
|
||
sub new { | ||
my $class = shift; | ||
bless { _class => $class }, $class; | ||
} | ||
|
||
package Foo::Mouse; | ||
use Mouse; | ||
use Any::Moose 'X::NonMoose'; | ||
extends 'Foo'; | ||
|
||
package main; | ||
my $foo = Foo->new; | ||
my $foo_moose = Foo::Mouse->new; | ||
isa_ok($foo, 'Foo'); | ||
is($foo->{_class}, 'Foo', 'Foo gets the correct class'); | ||
isa_ok($foo_moose, 'Foo::Mouse'); | ||
isa_ok($foo_moose, 'Foo'); | ||
isa_ok($foo_moose, 'Mouse::Object'); | ||
is($foo_moose->{_class}, 'Foo::Mouse', 'Foo::Mouse gets the correct class'); | ||
my $meta = Foo::Mouse->meta; | ||
ok($meta->has_method('new'), 'Foo::Mouse has its own constructor'); | ||
my $cc_meta = $meta->constructor_class->meta; | ||
isa_ok($cc_meta, 'Mouse::Meta::Class'); | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 3; | ||
|
||
package Foo; | ||
|
||
sub new { bless {}, shift } | ||
sub foo { 'Foo' } | ||
sub bar { 'Foo' } | ||
sub baz { ref(shift) } | ||
|
||
package Foo::Mouse; | ||
use Mouse; | ||
use Any::Moose 'X::NonMoose'; | ||
extends 'Foo'; | ||
|
||
sub bar { 'Foo::Mouse' } | ||
|
||
package main; | ||
|
||
my $foo_moose = Foo::Mouse->new; | ||
is($foo_moose->foo, 'Foo', 'Foo::Mouse->foo'); | ||
is($foo_moose->bar, 'Foo::Mouse', 'Foo::Mouse->bar'); | ||
is($foo_moose->baz, 'Foo::Mouse', 'Foo::Mouse->baz'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 4; | ||
|
||
package Foo; | ||
|
||
sub new { | ||
my $class = shift; | ||
bless { @_ }, $class; | ||
} | ||
|
||
sub foo { | ||
my $self = shift; | ||
return $self->{foo} unless @_; | ||
$self->{foo} = shift; | ||
} | ||
|
||
package Foo::Mouse; | ||
use Mouse; | ||
use Any::Moose 'X::NonMoose'; | ||
extends 'Foo'; | ||
|
||
has bar => ( | ||
is => 'rw', | ||
); | ||
|
||
package main; | ||
|
||
my $foo_moose = Foo::Mouse->new(foo => 'FOO', bar => 'BAR'); | ||
is($foo_moose->foo, 'FOO', 'foo set in constructor'); | ||
is($foo_moose->bar, 'BAR', 'bar set in constructor'); | ||
$foo_moose->foo('BAZ'); | ||
$foo_moose->bar('QUUX'); | ||
is($foo_moose->foo, 'BAZ', 'foo set by accessor'); | ||
is($foo_moose->bar, 'QUUX', 'bar set by accessor'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 11; | ||
|
||
package Foo; | ||
|
||
sub new { | ||
my $class = shift; | ||
bless { foo => 'FOO' }, $class; | ||
} | ||
|
||
sub foo { shift->{foo} } | ||
|
||
package Foo::Mouse; | ||
use Mouse; | ||
use Any::Moose 'X::NonMoose'; | ||
extends 'Foo'; | ||
|
||
has bar => ( | ||
is => 'ro', | ||
default => 'BAR', | ||
); | ||
|
||
package Foo::Mouse::Sub; | ||
use Mouse; | ||
extends 'Foo::Mouse'; | ||
|
||
has baz => ( | ||
is => 'ro', | ||
default => 'BAZ', | ||
); | ||
|
||
package main; | ||
my $foo_moose = Foo::Mouse->new; | ||
is($foo_moose->foo, 'FOO', 'Foo::Mouse::foo'); | ||
is($foo_moose->bar, 'BAR', 'Foo::Mouse::bar'); | ||
isnt(Foo::Mouse->meta->get_method('new'), undef, | ||
'Foo::Mouse gets its own constructor'); | ||
|
||
my $foo_moose_sub = Foo::Mouse::Sub->new; | ||
is($foo_moose_sub->foo, 'FOO', 'Foo::Mouse::Sub::foo'); | ||
is($foo_moose_sub->bar, 'BAR', 'Foo::Mouse::Sub::bar'); | ||
is($foo_moose_sub->baz, 'BAZ', 'Foo::Mouse::Sub::baz'); | ||
is(Foo::Mouse::Sub->meta->get_method('new'), undef, | ||
'Foo::Mouse::Sub just uses the constructor for Foo::Mouse'); | ||
|
||
Foo::Mouse->meta->make_immutable; | ||
Foo::Mouse::Sub->meta->make_immutable; | ||
|
||
$foo_moose_sub = Foo::Mouse::Sub->new; | ||
is($foo_moose_sub->foo, 'FOO', 'Foo::Mouse::Sub::foo (immutable)'); | ||
is($foo_moose_sub->bar, 'BAR', 'Foo::Mouse::Sub::bar (immutable)'); | ||
is($foo_moose_sub->baz, 'BAZ', 'Foo::Mouse::Sub::baz (immutable)'); | ||
isnt(Foo::Mouse::Sub->meta->get_method('new'), undef, | ||
'Foo::Mouse::Sub has an inlined constructor'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 12; | ||
|
||
package Foo; | ||
use Mouse; | ||
|
||
has foo => ( | ||
is => 'ro', | ||
default => 'FOO', | ||
); | ||
|
||
package Foo::Sub; | ||
use Mouse; | ||
use Any::Moose 'X::NonMoose'; | ||
extends 'Foo'; | ||
|
||
package main; | ||
my $foo_sub = Foo::Sub->new; | ||
isa_ok($foo_sub, 'Foo'); | ||
is($foo_sub->foo, 'FOO', 'inheritance works'); | ||
ok(!Foo::Sub->meta->has_method('new'), | ||
'Foo::Sub doesn\'t have its own new method'); | ||
|
||
$_->meta->make_immutable for qw(Foo Foo::Sub); | ||
|
||
$foo_sub = Foo::Sub->new; | ||
isa_ok($foo_sub, 'Foo'); | ||
is($foo_sub->foo, 'FOO', 'inheritance works (immutable)'); | ||
ok(Foo::Sub->meta->has_method('new'), | ||
'Foo::Sub has its own new method (immutable)'); | ||
|
||
package Foo::OtherSub; | ||
use Mouse; | ||
use Any::Moose 'X::NonMoose'; | ||
extends 'Foo'; | ||
|
||
package main; | ||
my $foo_othersub = Foo::OtherSub->new; | ||
isa_ok($foo_othersub, 'Foo'); | ||
is($foo_othersub->foo, 'FOO', 'inheritance works (immutable when extending)'); | ||
ok(!Foo::OtherSub->meta->has_method('new'), | ||
'Foo::OtherSub doesn\'t have its own new method (immutable when extending)'); | ||
|
||
Foo::OtherSub->meta->make_immutable; | ||
$foo_othersub = Foo::OtherSub->new; | ||
isa_ok($foo_othersub, 'Foo'); | ||
is($foo_othersub->foo, 'FOO', 'inheritance works (all immutable)'); | ||
ok(Foo::OtherSub->meta->has_method('new'), | ||
'Foo::OtherSub has its own new method (all immutable)'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 3; | ||
|
||
package Foo; | ||
|
||
sub new { | ||
my $class = shift; | ||
bless {}, $class; | ||
} | ||
|
||
package Foo::Mouse; | ||
use Mouse; | ||
use Any::Moose 'X::NonMoose'; | ||
extends 'Foo'; | ||
|
||
package Foo::Mouse2; | ||
use Mouse; | ||
use Any::Moose 'X::NonMoose'; | ||
extends 'Foo'; | ||
|
||
package main; | ||
|
||
ok(Foo::Mouse->meta->has_method('new'), 'Foo::Mouse has a constructor'); | ||
my $method = Foo::Mouse->meta->get_method('new'); | ||
Foo::Mouse->meta->make_immutable; | ||
isnt($method->body, Foo::Mouse->meta->get_method('new')->body, | ||
'make_immutable replaced the constructor with an inlined version'); | ||
|
||
my $method2 = Foo::Mouse2->meta->get_method('new'); | ||
Foo::Mouse2->meta->make_immutable(inline_constructor => 0); | ||
is($method2->body, Foo::Mouse2->meta->get_method('new')->body, | ||
'make_immutable doesn\'t replace the constructor if we ask it not to'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use Test::More tests => 6; | ||
|
||
package Foo; | ||
|
||
sub new { | ||
my $class = shift; | ||
bless { @_ }, $class; | ||
} | ||
|
||
sub foo { | ||
my $self = shift; | ||
return $self->{foo} unless @_; | ||
$self->{foo} = shift; | ||
} | ||
|
||
sub baz { 'Foo' } | ||
sub quux { ref(shift) } | ||
|
||
package Foo::Mouse; | ||
use Mouse; | ||
use Any::Moose 'X::NonMoose'; | ||
extends 'Foo'; | ||
|
||
has bar => ( | ||
is => 'rw', | ||
); | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
|
||
package main; | ||
|
||
my $foo_moose = Foo::Mouse->new(foo => 'FOO', bar => 'BAR'); | ||
is($foo_moose->foo, 'FOO', 'foo set in constructor'); | ||
is($foo_moose->bar, 'BAR', 'bar set in constructor'); | ||
$foo_moose->foo('BAZ'); | ||
$foo_moose->bar('QUUX'); | ||
is($foo_moose->foo, 'BAZ', 'foo set by accessor'); | ||
is($foo_moose->bar, 'QUUX', 'bar set by accessor'); | ||
is($foo_moose->baz, 'Foo', 'baz method'); | ||
is($foo_moose->quux, 'Foo::Mouse', 'quux method'); |
Oops, something went wrong.