From: Todd Hepler Date: Tue, 30 Sep 2008 15:35:47 +0000 (+0000) Subject: make sure we can create an anon class that has a required attribute X-Git-Tag: 0.59~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=310ba883f93de0f2795d8daf2b7b8d17763fa2c1;p=gitmo%2FMoose.git make sure we can create an anon class that has a required attribute this will require the previous commit to Class::MOP (that will become version 0.67) --- diff --git a/Changes b/Changes index 5af3c2c..8412e68 100644 --- a/Changes +++ b/Changes @@ -11,8 +11,12 @@ Revision history for Perl extension Moose - Some tests that used Test::Warn if it was available failed with older versions of Test::Warn. Reported by Fayland. (Dave Rolsky) + * Moose::Meta::Class + - In create(), do not pass "roles" option to the superclass + - added related test that creates an anon metaclass with + a required attribute -0.58 +0.58 Sat September 20, 2008 !! This release has an incompatible change regarding !! !! how roles add methods to a class !! diff --git a/MANIFEST b/MANIFEST index 3282156..8cecfe9 100644 --- a/MANIFEST +++ b/MANIFEST @@ -207,6 +207,7 @@ t/050_metaclasses/015_metarole.t t/050_metaclasses/016_metarole_w_metaclass_pm.t t/050_metaclasses/017_use_base_of_moose.t t/050_metaclasses/018_throw_error.t +t/050_metaclasses/019_create_anon_with_required_attr.t t/060_compat/001_module_refresh_compat.t t/060_compat/002_moose_respects_base.t t/060_compat/003_foreign_inheritence.t diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 9975650..ebe618a 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -60,11 +60,12 @@ sub create { (ref $options{roles} eq 'ARRAY') || $self->throw_error("You must pass an ARRAY ref of roles", data => $options{roles}) if exists $options{roles}; + my $roles = delete $options{roles}; my $class = $self->SUPER::create($package_name, %options); - if (exists $options{roles}) { - Moose::Util::apply_all_roles($class, @{$options{roles}}); + if ($roles) { + Moose::Util::apply_all_roles( $class, @$roles ); } return $class; diff --git a/t/050_metaclasses/019_create_anon_with_required_attr.t b/t/050_metaclasses/019_create_anon_with_required_attr.t new file mode 100644 index 0000000..37e340c --- /dev/null +++ b/t/050_metaclasses/019_create_anon_with_required_attr.t @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 3; +use Test::Exception; + +{ + package HasFoo; + use Moose::Role; + has 'foo' => ( + is => 'ro', + isa => 'Str', + required => 1, + ); + +} + +{ + package My::Metaclass; + use Moose; + extends 'Moose::Meta::Class'; + with 'HasFoo'; +} + +package main; + +my $anon; +lives_ok { + $anon = My::Metaclass->create_anon_class( foo => 'this' ); +} 'create anon class'; +isa_ok( $anon, 'My::Metaclass' ); +cmp_ok( $anon->foo, 'eq', 'this', 'foo is this' ); +