- added Bool type and CollectionRef type
then made ArrayRef and HashRef into subtypes
of the CollectionRef
+ - keywords are now exported with Sub::Exporter
+ thanks chansen for this commit
0.04 Sun. April 16th, 2006
* Moose::Role
}
elsif ($options{is} eq 'rw') {
$options{accessor} = $name;
- (reftype($options{trigger}) eq 'CODE')
+ ((reftype($options{trigger}) || '') eq 'CODE')
|| confess "A trigger must be a CODE reference"
if exists $options{trigger};
}
($options{isa}->does($options{does}))
|| confess "Cannot have an isa option and a does option if the isa does not do the does";
}
+ else {
+ confess "Cannot have an isa option which cannot ->does()";
+ }
}
# allow for anon-subtypes here ...
our $VERSION = '0.03';
use Moose::Meta::Role;
+use Moose::Util::TypeConstraints;
{
my ( $CALLER, %METAS );
sub _find_meta {
- my $class = $CALLER;
+ my $role = $CALLER;
- return $METAS{$class} if exists $METAS{$class};
+ return $METAS{$role} if exists $METAS{$role};
+
+ # make a subtype for each Moose class
+ subtype $role
+ => as 'Role'
+ => where { $_->does($role) }
+ unless find_type_constraint($role);
my $meta;
- if ($class->can('meta')) {
- $meta = $class->meta();
+ if ($role->can('meta')) {
+ $meta = $role->meta();
(blessed($meta) && $meta->isa('Moose::Meta::Role'))
|| confess "Whoops, not møøsey enough";
}
else {
- $meta = Moose::Meta::Role->new(role_name => $class);
+ $meta = Moose::Meta::Role->new(role_name => $role);
$meta->_role_meta->add_method('meta' => sub { $meta })
}
- return $METAS{$class} = $meta;
+ return $METAS{$role} = $meta;
}
use lib 't/lib', 'lib';
-use Test::More tests => 4;
+use Test::More tests => 6;
BEGIN {
use_ok('Moose');
::ok(!$@, '... loaded Foo and (inline) Bar superclass correctly');
}
+{
+ package Bling;
+ use strict;
+ use warnings;
+ use Moose;
+
+ eval { extends 'No::Class'; };
+ ::ok($@, '... could not find the superclass (as expected)');
+ ::like($@, qr/^Could not load superclass 'No\:\:Class' because \:/, '... and got the error we expected');
+}
+
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+use Test::Exception;
+
+BEGIN {
+ use_ok('Moose');
+}
+
+
+{
+ package Foo::Meta;
+ use strict;
+ use warnings;
+
+ use base 'Moose::Meta::Class';
+
+ package Foo;
+ use strict;
+ use warnings;
+ use metaclass 'Foo::Meta';
+ ::use_ok('Moose');
+}
+
+isa_ok(Foo->meta, 'Foo::Meta');
+
+{
+ package Bar::Meta;
+ use strict;
+ use warnings;
+
+ use base 'Class::MOP::Class';
+
+ package Bar;
+ use strict;
+ use warnings;
+ use metaclass 'Bar::Meta';
+ eval 'use Moose;';
+ ::ok($@, '... could not load moose without correct metaclass');
+ ::like($@, qr/^Whoops\, not møøsey enough/, '... got the right error too');
+}
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+use Test::Exception;
+
+BEGIN {
+ use_ok('Moose');
+}
+
+{
+ package Foo;
+ use strict;
+ use warnings;
+
+ sub foo { 'Foo::foo' }
+
+ package Bar;
+ use strict;
+ use warnings;
+ use Moose;
+
+ use base 'Foo';
+}
+
+my $bar = Bar->new;
+isa_ok($bar, 'Bar');
+isa_ok($bar, 'Foo');
\ No newline at end of file
use Scalar::Util 'isweak';
-use Test::More tests => 24;
+use Test::More tests => 27;
use Test::Exception;
BEGIN {
ok(isweak($baz->{foo}), '... baz.foo is a weak reference');
}
+# some errors
+
+{
+ package Bling;
+ use strict;
+ use warnings;
+ use Moose;
+
+ ::dies_ok {
+ has('bling' => (is => 'ro', trigger => sub { 0 }));
+ } '... cannot create trigger on a read-only attr';
+}
+
+{
+ package Bling::Bling;
+ use strict;
+ use warnings;
+ use Moose;
+
+ ::dies_ok {
+ has('bling' => (is => 'rw', trigger => 'Fail'));
+ } '... a trigger must be a CODE ref';
+
+ ::dies_ok {
+ has('bling' => (is => 'rw', trigger => []));
+ } '... a trigger must be a CODE ref';
+}
+
+
use strict;
use warnings;
-use Test::More tests => 7;
+use Test::More tests => 8;
use Test::Exception;
BEGIN {
has 'foo' => (isa => 'Foo::Class', does => 'Bar::Class');
} '... cannot have a does() which is not done by the isa()';
}
+
+{
+ package Bling;
+ use strict;
+ use warnings;
+
+ sub bling { 'Bling::bling' }
+
+ package Bling::Bling;
+ use strict;
+ use warnings;
+ use Moose;
+
+ # if isa and does appear together, then see if Class->does(Role)
+ # if it does not,.. we have a conflict... so we die loudly
+ ::dies_ok {
+ has 'foo' => (isa => 'Bling', does => 'Bar::Class');
+ } '... cannot have a isa() which is cannot does()';
+}
+
+