* Moose::Cookbook::Snacks::*
- removed some of the unfinished snacks that should
not have been released yet. Added some more examples
- and explination to the 'Keywords' snack. (Stevan)
+ and explination to the 'Keywords' snack. (stevan)
* Moose
- added "FEATURE REQUESTS" section to the Moose docs
- to properly direct people (Stevan) (RT #34333)
+ to properly direct people (stevan) (RT #34333)
+ - making 'extends' croak if it is passed a Role since
+ this is not ever something you want to do
+ (fixed by stevan, found by obra)
+ - added tests for this (stevan)
* Moose::Cookbook::Style
- added general Moose "style guide" of sorts to the
cookbook (nothingmuch) (RT #34335)
+ * t/
+ - added more BUILDARGS tests (stevan)
+
0.51 Thurs. Jun 26, 2008
* Moose::Role
- add unimport so "no Moose::Role" actually does
my @supers = @_;
foreach my $super (@supers) {
Class::MOP::load_class($super);
+ croak "You cannot inherit from a Moose Role ($super)"
+ if $super->can('meta') &&
+ blessed $super->meta &&
+ $super->meta->isa('Moose::Meta::Role')
}
+
+
# this checks the metaclass to make sure
# it is correct, sometimes it can get out
# of sync when the classes are being built
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 14;
+
+{
+ package Foo;
+ use Moose;
+
+ has bar => ( is => "rw" );
+ has baz => ( is => "rw" );
+
+ sub BUILDARGS {
+ my ( $self, @args ) = @_;
+ unshift @args, "bar" if @args % 2 == 1;
+ return {@args};
+ }
+
+ package Bar;
+ use Moose;
+
+ extends qw(Foo);
+}
+
+foreach my $class qw(Foo Bar) {
+ is( $class->new->bar, undef, "no args" );
+ is( $class->new( bar => 42 )->bar, 42, "normal args" );
+ is( $class->new( 37 )->bar, 37, "single arg" );
+ {
+ my $o = $class->new(bar => 42, baz => 47);
+ is($o->bar, 42, '... got the right bar');
+ is($o->baz, 47, '... got the right bar');
+ }
+ {
+ my $o = $class->new(42, baz => 47);
+ is($o->bar, 42, '... got the right bar');
+ is($o->baz, 47, '... got the right bar');
+ }
+}
+
+
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+use Test::Exception;
+
+BEGIN {
+ use_ok('Moose');
+}
+
+{
+ package My::Role;
+ use Moose::Role;
+}
+{
+ package My::Class;
+ use Moose;
+
+ ::throws_ok {
+ extends 'My::Role';
+ } qr/You cannot inherit from a Moose Role \(My\:\:Role\)/,
+ '... this croaks correctly';
+}
use strict;
use warnings;
-use Test::More 'no_plan';
+use Test::More tests => 14;
{
package Foo;
use Moose;
has bar => ( is => "rw" );
+ has baz => ( is => "rw" );
sub BUILDARGS {
my ( $self, @args ) = @_;
return {@args};
}
+ __PACKAGE__->meta->make_immutable;
+
package Bar;
use Moose;
extends qw(Foo);
-
+
__PACKAGE__->meta->make_immutable;
}
is( $class->new->bar, undef, "no args" );
is( $class->new( bar => 42 )->bar, 42, "normal args" );
is( $class->new( 37 )->bar, 37, "single arg" );
+ {
+ my $o = $class->new(bar => 42, baz => 47);
+ is($o->bar, 42, '... got the right bar');
+ is($o->baz, 47, '... got the right bar');
+ }
+ {
+ my $o = $class->new(42, baz => 47);
+ is($o->bar, 42, '... got the right bar');
+ is($o->baz, 47, '... got the right bar');
+ }
}
+
+