From: Stevan Little Date: Thu, 31 May 2007 03:50:09 +0000 (+0000) Subject: for mst and castaway X-Git-Tag: 0_23~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=86629f931a82f81359c8a59523cd71714fd196b8;p=gitmo%2FMoose.git for mst and castaway --- diff --git a/Changes b/Changes index f68052e..abca9e7 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,9 @@ Revision history for Perl extension Moose - added the ClassName type constraint, this checks for strings which will respond true to ->isa(UNIVERSAL). - added tests and docs for this + - subtyping just in name now works correctly by making the + default for where be { 1 } + - added test for this * Moose::Meta::Method::Accessor - coerce and lazy now work together correctly, thanks to @@ -15,6 +18,12 @@ Revision history for Perl extension Moose - tests added for this - fix reader presedence bug in Moose::Meta::Attribute + tests + * Moose::Object + - Foo->new(undef) now gets ignored, it is assumed you meant to pass + a HASH-ref and missed. This produces better error messages then + having it die cause undef is not a HASH. + - added tests for this + 0.21 Thursday, May 2nd, 2007 * Moose - added SUPER_SLOT and INNER_SLOT class hashes to support unimport diff --git a/MANIFEST b/MANIFEST index a58e266..53a5c60 100644 --- a/MANIFEST +++ b/MANIFEST @@ -81,6 +81,7 @@ t/055_util_type_reloading.t t/056_util_more_type_coercion.t t/057_union_types.t t/058_union_types_and_coercions.t +t/059_misc_type_tests.t t/060_moose_for_meta.t t/070_more_attr_delegation.t t/071_misc_attribute_tests.t @@ -94,11 +95,15 @@ t/104_inline_reader_bug.t t/105_module_refresh_compat.t t/106_handles_foreign_class_bug.t t/107_custom_attr_meta_with_roles.t +t/108_custom_attr_meta_as_role.t +t/109_reader_precedence_bug.t +t/110_new_w_undef.t t/201_example.t t/202_example_Moose_POOP.t t/203_example.t t/204_example_w_DCS.t t/205_example_w_TestDeep.t +t/206_example_Protomoose.t t/300_immutable_moose.t t/pod.t t/pod_coverage.t diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index b54a89a..fe22744 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -9,16 +9,18 @@ use metaclass 'Moose::Meta::Class'; use Carp 'confess'; -our $VERSION = '0.08'; +our $VERSION = '0.09'; our $AUTHORITY = 'cpan:STEVAN'; sub new { my $class = shift; my %params; if (scalar @_ == 1) { - (ref($_[0]) eq 'HASH') - || confess "Single parameters to new() must be a HASH ref"; - %params = %{$_[0]}; + if (defined $_[0]) { + (ref($_[0]) eq 'HASH') + || confess "Single parameters to new() must be a HASH ref"; + %params = %{$_[0]}; + } } else { %params = @_; diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 9dfa98b..61531cb 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Carp 'confess'; -use Scalar::Util 'blessed'; +use Scalar::Util 'blessed', 'reftype'; use B 'svref_2object'; use Sub::Exporter; @@ -83,7 +83,7 @@ sub unimport { sub _create_type_constraint ($$$;$$) { my $name = shift; my $parent = shift; - my $check = shift;; + my $check = shift || sub { 1 }; my ($message, $optimized); for (@_) { @@ -153,7 +153,16 @@ sub type ($$;$$) { } sub subtype ($$;$$$) { - unshift @_ => undef if scalar @_ <= 2; + # NOTE: + # this adds an undef for the name + # if this is an anon-subtype: + # subtype(Num => where { $_ % 2 == 0 }) # anon 'even' subtype + # but if the last arg is not a code + # ref then it is a subtype alias: + # subtype(MyNumbers => as Num); # now MyNumbers is the same as Num + # ... yeah I know it's ugly code + # - SL + unshift @_ => undef if scalar @_ <= 2 && (reftype($_[1]) || '') eq 'CODE'; goto &_create_type_constraint; } diff --git a/t/059_misc_type_tests.t b/t/059_misc_type_tests.t new file mode 100644 index 0000000..8e7a1cf --- /dev/null +++ b/t/059_misc_type_tests.t @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 3; +use Test::Exception; + +BEGIN { + use_ok('Moose::Util::TypeConstraints'); +} + +# subtype 'aliasing' ... + +lives_ok { + subtype 'Numb3rs' => as 'Num'; +} '... create bare subtype fine'; + +my $numb3rs = find_type_constraint('Numb3rs'); +isa_ok($numb3rs, 'Moose::Meta::TypeConstraint'); \ No newline at end of file diff --git a/t/110_new_w_undef.t b/t/110_new_w_undef.t new file mode 100644 index 0000000..58d7074 --- /dev/null +++ b/t/110_new_w_undef.t @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Moose; + +use Test::More tests => 1; +use Test::Exception; + +{ + package Foo; + use Moose; + has 'foo' => ( is => 'ro' ); +} + +lives_ok { + Foo->new(undef); +} '... passing in undef just gets ignored'; + + + +