Merge branch 'master' of moose.perl.org:Mouse
gfx [Sat, 9 Jan 2010 07:42:42 +0000 (16:42 +0900)]
benchmarks/coercion.pl
benchmarks/subtype.pl
t/001_mouse/044-attribute-metaclass.t
t/001_mouse/055-exporter.t
t/001_mouse/056-role-combine.t
t/010_basics/failing/020-global-destruction-helper.pl
t/040_type_constraints/017_subtyping_union_types.t
t/900_bug/004_RT53286.t [new file with mode: 0755]
xs-src/MouseAccessor.xs

index a473303..ce1643d 100755 (executable)
@@ -7,15 +7,15 @@ use Benchmark qw/cmpthese/;
 for my $klass (qw/Moose Mouse/) {
     eval qq{
         package ${klass}One;
-        use $klass;\r
+        use $klass;
         use ${klass}::Util::TypeConstraints;
-\r
+
         subtype 'NaturalNumber', as 'Int', where { \$_ > 0 };
 
         coerce 'NaturalNumber',
             from 'Str', via { 42 },
-        ;\r
-\r
+        ;
+
         has n => (
             is     => 'rw',
             isa    => 'NaturalNumber',
index 90a0cf3..1539950 100755 (executable)
@@ -6,11 +6,11 @@ use Benchmark qw/cmpthese/;
 for my $klass (qw/Moose Mouse/) {
     eval qq{
         package ${klass}One;
-        use $klass;\r
+        use $klass;
         use ${klass}::Util::TypeConstraints;
-\r
-        subtype 'NaturalNumber', as 'Int', where { \$_ > 0 };\r
-\r
+
+        subtype 'NaturalNumber', as 'Int', where { \$_ > 0 };
+
         has n => (
             is  => 'rw',
             isa => 'NaturalNumber',
index 4c0c38d..f31e89d 100644 (file)
@@ -203,48 +203,48 @@ do {
 
     sub helper_type { 'Num' }
 
-    has 'method_constructors' => (\r
-        is      => 'ro',\r
-        isa     => 'HashRef',\r
-        lazy    => 1,\r
-        default => sub {\r
-            return +{\r
-                set => sub {\r
-                    my ( $attr, $reader, $writer ) = @_;\r
-                    return sub { $writer->( $_[0], $_[1] ) };\r
+    has 'method_constructors' => (
+        is      => 'ro',
+        isa     => 'HashRef',
+        lazy    => 1,
+        default => sub {
+            return +{
+                set => sub {
+                    my ( $attr, $reader, $writer ) = @_;
+                    return sub { $writer->( $_[0], $_[1] ) };
+                },
+                get => sub {
+                    my ( $attr, $reader, $writer ) = @_;
+                    return sub { $reader->( $_[0] ) };
+                },
+                add => sub {
+                    my ( $attr, $reader, $writer ) = @_;
+                    return sub { $writer->( $_[0], $reader->( $_[0] ) + $_[1] ) };
                 },
-                get => sub {\r
-                    my ( $attr, $reader, $writer ) = @_;\r
-                    return sub { $reader->( $_[0] ) };\r
+                sub => sub {
+                    my ( $attr, $reader, $writer ) = @_;
+                    return sub { $writer->( $_[0], $reader->( $_[0] ) - $_[1] ) };
                 },
-                add => sub {\r
-                    my ( $attr, $reader, $writer ) = @_;\r
-                    return sub { $writer->( $_[0], $reader->( $_[0] ) + $_[1] ) };\r
-                },\r
-                sub => sub {\r
-                    my ( $attr, $reader, $writer ) = @_;\r
-                    return sub { $writer->( $_[0], $reader->( $_[0] ) - $_[1] ) };\r
-                },\r
-                mul => sub {\r
-                    my ( $attr, $reader, $writer ) = @_;\r
-                    return sub { $writer->( $_[0], $reader->( $_[0] ) * $_[1] ) };\r
-                },\r
-                div => sub {\r
-                    my ( $attr, $reader, $writer ) = @_;\r
-                    return sub { $writer->( $_[0], $reader->( $_[0] ) / $_[1] ) };\r
-                },\r
-                mod => sub {\r
-                    my ( $attr, $reader, $writer ) = @_;\r
-                    return sub { $writer->( $_[0], $reader->( $_[0] ) % $_[1] ) };\r
-                },\r
-                abs => sub {\r
-                    my ( $attr, $reader, $writer ) = @_;\r
-                    return sub { $writer->( $_[0], abs( $reader->( $_[0] ) ) ) };\r
-                },\r
-            };\r
-        }\r
-    );\r
-\r
+                mul => sub {
+                    my ( $attr, $reader, $writer ) = @_;
+                    return sub { $writer->( $_[0], $reader->( $_[0] ) * $_[1] ) };
+                },
+                div => sub {
+                    my ( $attr, $reader, $writer ) = @_;
+                    return sub { $writer->( $_[0], $reader->( $_[0] ) / $_[1] ) };
+                },
+                mod => sub {
+                    my ( $attr, $reader, $writer ) = @_;
+                    return sub { $writer->( $_[0], $reader->( $_[0] ) % $_[1] ) };
+                },
+                abs => sub {
+                    my ( $attr, $reader, $writer ) = @_;
+                    return sub { $writer->( $_[0], abs( $reader->( $_[0] ) ) ) };
+                },
+            };
+        }
+    );
+
 
     package MouseX::AttributeHelpers::Number;
     use Mouse;
index 7f945c6..1207c42 100644 (file)
@@ -1,81 +1,81 @@
-#!perl\r
-use strict;\r
-use warnings;\r
-use Test::More tests => 14;\r
-\r
-use Mouse ();\r
-\r
-BEGIN{\r
-    package MyMouse;\r
-    use Mouse;\r
-    Mouse::Exporter->setup_import_methods(\r
-        as_is => [qw(foo)],\r
-        also  => [qw(Mouse)],\r
-    );\r
-\r
-    sub foo{ 100 }\r
-\r
-    $INC{'MyMouse.pm'}++;\r
-\r
-    package MyMouseEx;\r
-    use Mouse;\r
-    Mouse::Exporter->setup_import_methods(\r
-        as_is => [\&bar],\r
-        also  => [qw(MyMouse)],\r
-\r
-#        groups => {\r
-#            foobar_only => [qw(foo bar)],\r
-#        },\r
-    );\r
-\r
-    sub bar{ 200 }\r
-\r
-    $INC{'MyMouseEx.pm'}++;\r
-}\r
-\r
-can_ok 'MyMouse',   qw(import unimport);\r
-can_ok 'MyMouseEx', qw(import unimport);\r
-\r
-{\r
-    package MyApp;\r
-    use Test::More;\r
-    use MyMouse;\r
-\r
-    can_ok __PACKAGE__, 'meta';\r
-    ok defined(&foo), 'foo is imported';\r
-    ok defined(&has), 'has is also imported';\r
-\r
-    no MyMouse;\r
-\r
-    ok !defined(&foo), 'foo is unimported';\r
-    ok !defined(&has), 'has is also unimported';\r
-}\r
-{\r
-    package MyAppEx;\r
-    use Test::More;\r
-    use MyMouseEx;\r
-\r
-    can_ok __PACKAGE__, 'meta';\r
-    ok defined(&foo), 'foo is imported';\r
-    ok defined(&bar), 'foo is also imported';\r
-    ok defined(&has), 'has is also imported';\r
-\r
-    no MyMouseEx;\r
-\r
-    ok !defined(&foo), 'foo is unimported';\r
-    ok !defined(&bar), 'foo is also unimported';\r
-    ok !defined(&has), 'has is also unimported';\r
-}\r
-\r
-# exporting groups are not implemented in Moose::Exporter\r
-#{\r
-#    package MyAppExTags;\r
-#    use Test::More;\r
-#    use MyMouseEx qw(:foobar_only);\r
-#\r
-#    can_ok __PACKAGE__, 'meta';\r
-#    ok defined(&foo);\r
-#    ok defined(&bar);\r
-#    ok!defined(&has), "export tags";\r
-#}\r
-\r
+#!perl
+use strict;
+use warnings;
+use Test::More tests => 14;
+
+use Mouse ();
+
+BEGIN{
+    package MyMouse;
+    use Mouse;
+    Mouse::Exporter->setup_import_methods(
+        as_is => [qw(foo)],
+        also  => [qw(Mouse)],
+    );
+
+    sub foo{ 100 }
+
+    $INC{'MyMouse.pm'}++;
+
+    package MyMouseEx;
+    use Mouse;
+    Mouse::Exporter->setup_import_methods(
+        as_is => [\&bar],
+        also  => [qw(MyMouse)],
+
+#        groups => {
+#            foobar_only => [qw(foo bar)],
+#        },
+    );
+
+    sub bar{ 200 }
+
+    $INC{'MyMouseEx.pm'}++;
+}
+
+can_ok 'MyMouse',   qw(import unimport);
+can_ok 'MyMouseEx', qw(import unimport);
+
+{
+    package MyApp;
+    use Test::More;
+    use MyMouse;
+
+    can_ok __PACKAGE__, 'meta';
+    ok defined(&foo), 'foo is imported';
+    ok defined(&has), 'has is also imported';
+
+    no MyMouse;
+
+    ok !defined(&foo), 'foo is unimported';
+    ok !defined(&has), 'has is also unimported';
+}
+{
+    package MyAppEx;
+    use Test::More;
+    use MyMouseEx;
+
+    can_ok __PACKAGE__, 'meta';
+    ok defined(&foo), 'foo is imported';
+    ok defined(&bar), 'foo is also imported';
+    ok defined(&has), 'has is also imported';
+
+    no MyMouseEx;
+
+    ok !defined(&foo), 'foo is unimported';
+    ok !defined(&bar), 'foo is also unimported';
+    ok !defined(&has), 'has is also unimported';
+}
+
+# exporting groups are not implemented in Moose::Exporter
+#{
+#    package MyAppExTags;
+#    use Test::More;
+#    use MyMouseEx qw(:foobar_only);
+#
+#    can_ok __PACKAGE__, 'meta';
+#    ok defined(&foo);
+#    ok defined(&bar);
+#    ok!defined(&has), "export tags";
+#}
+
index 6ebe4e3..c195d59 100644 (file)
@@ -1,35 +1,35 @@
-#!perl\r
-use strict;\r
-use warnings;\r
-use Test::More tests => 2;\r
-use Test::Exception;\r
-{\r
-    package RoleA;\r
-    use Mouse::Role;\r
-\r
-    sub foo { }\r
-    sub bar { }\r
-}\r
-{\r
-    package RoleB;\r
-    use Mouse::Role;\r
-\r
-    sub foo { }\r
-    sub bar { }\r
-}\r
-{\r
-    package Class;\r
-    use Mouse;\r
-    use Test::More;\r
-    use Test::Exception;\r
-\r
-    throws_ok {\r
-        with qw(RoleA RoleB);\r
-    } qr/Due to method name conflicts in roles 'RoleA' and 'RoleB', the methods 'bar' and 'foo' must be/;\r
-\r
-    lives_ok {\r
-        with RoleA => { -excludes => ['foo'] },\r
-             RoleB => { -excludes => ['bar'] },\r
-        ;\r
-    };\r
-}\r
+#!perl
+use strict;
+use warnings;
+use Test::More tests => 2;
+use Test::Exception;
+{
+    package RoleA;
+    use Mouse::Role;
+
+    sub foo { }
+    sub bar { }
+}
+{
+    package RoleB;
+    use Mouse::Role;
+
+    sub foo { }
+    sub bar { }
+}
+{
+    package Class;
+    use Mouse;
+    use Test::More;
+    use Test::Exception;
+
+    throws_ok {
+        with qw(RoleA RoleB);
+    } qr/Due to method name conflicts in roles 'RoleA' and 'RoleB', the methods 'bar' and 'foo' must be/;
+
+    lives_ok {
+        with RoleA => { -excludes => ['foo'] },
+             RoleB => { -excludes => ['bar'] },
+        ;
+    };
+}
index a0defbe..7c30edd 100755 (executable)
@@ -1,34 +1,34 @@
-#!/usr/bin/perl\r
-\r
-use strict;\r
-use warnings;\r
-\r
-\r
-{\r
-    package Foo;\r
-    use Mouse;\r
-\r
-    sub DEMOLISH {\r
-        my $self = shift;\r
-        my ($igd) = @_;\r
-\r
-        print $igd;\r
-    }\r
-}\r
-\r
-{\r
-    package Bar;\r
-    use Mouse;\r
-\r
-    sub DEMOLISH {\r
-        my $self = shift;\r
-        my ($igd) = @_;\r
-\r
-        print $igd;\r
-    }\r
-\r
-    __PACKAGE__->meta->make_immutable;\r
-}\r
-\r
-our $foo = Foo->new;\r
-our $bar = Bar->new;\r
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+
+{
+    package Foo;
+    use Mouse;
+
+    sub DEMOLISH {
+        my $self = shift;
+        my ($igd) = @_;
+
+        print $igd;
+    }
+}
+
+{
+    package Bar;
+    use Mouse;
+
+    sub DEMOLISH {
+        my $self = shift;
+        my ($igd) = @_;
+
+        print $igd;
+    }
+
+    __PACKAGE__->meta->make_immutable;
+}
+
+our $foo = Foo->new;
+our $bar = Bar->new;
index 505e92c..830f1e8 100755 (executable)
@@ -1,69 +1,69 @@
-#!/usr/bin/perl\r
-\r
-use strict;\r
-use warnings;\r
-\r
-use Test::More tests => 19;\r
-use Test::Exception;\r
-\r
-BEGIN {\r
-    use_ok("Mouse::Util::TypeConstraints");\r
-}\r
-\r
-lives_ok {\r
-    subtype 'MyCollections' => as 'ArrayRef | HashRef';\r
-} '... created the subtype special okay';\r
-\r
-{\r
-    my $t = find_type_constraint('MyCollections');\r
-    isa_ok($t, 'Mouse::Meta::TypeConstraint');\r
-\r
-    is($t->name, 'MyCollections', '... name is correct');\r
-\r
-    my $p = $t->parent;\r
-#    isa_ok($p, 'Mouse::Meta::TypeConstraint::Union');\r
-    isa_ok($p, 'Mouse::Meta::TypeConstraint');\r
-\r
-    is($p->name, 'ArrayRef|HashRef', '... parent name is correct');\r
-\r
-    ok($t->check([]), '... validated it correctly');\r
-    ok($t->check({}), '... validated it correctly');\r
-    ok(!$t->check(1), '... validated it correctly');\r
-}\r
-\r
-lives_ok {\r
-    subtype 'MyCollectionsExtended'\r
-        => as 'ArrayRef|HashRef'\r
-        => where {\r
-            if (ref($_) eq 'ARRAY') {\r
-                return if scalar(@$_) < 2;\r
-            }\r
-            elsif (ref($_) eq 'HASH') {\r
-                return if scalar(keys(%$_)) < 2;\r
-            }\r
-            1;\r
-        };\r
-} '... created the subtype special okay';\r
-\r
-{\r
-    my $t = find_type_constraint('MyCollectionsExtended');\r
-    isa_ok($t, 'Mouse::Meta::TypeConstraint');\r
-\r
-    is($t->name, 'MyCollectionsExtended', '... name is correct');\r
-\r
-    my $p = $t->parent;\r
-#    isa_ok($p, 'Mouse::Meta::TypeConstraint::Union');\r
-    isa_ok($p, 'Mouse::Meta::TypeConstraint');\r
-\r
-    is($p->name, 'ArrayRef|HashRef', '... parent name is correct');\r
-\r
-    ok(!$t->check([]), '... validated it correctly');\r
-    ok($t->check([1, 2]), '... validated it correctly');\r
-\r
-    ok(!$t->check({}), '... validated it correctly');\r
-    ok($t->check({ one => 1, two => 2 }), '... validated it correctly');\r
-\r
-    ok(!$t->check(1), '... validated it correctly');\r
-}\r
-\r
-\r
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 19;
+use Test::Exception;
+
+BEGIN {
+    use_ok("Mouse::Util::TypeConstraints");
+}
+
+lives_ok {
+    subtype 'MyCollections' => as 'ArrayRef | HashRef';
+} '... created the subtype special okay';
+
+{
+    my $t = find_type_constraint('MyCollections');
+    isa_ok($t, 'Mouse::Meta::TypeConstraint');
+
+    is($t->name, 'MyCollections', '... name is correct');
+
+    my $p = $t->parent;
+#    isa_ok($p, 'Mouse::Meta::TypeConstraint::Union');
+    isa_ok($p, 'Mouse::Meta::TypeConstraint');
+
+    is($p->name, 'ArrayRef|HashRef', '... parent name is correct');
+
+    ok($t->check([]), '... validated it correctly');
+    ok($t->check({}), '... validated it correctly');
+    ok(!$t->check(1), '... validated it correctly');
+}
+
+lives_ok {
+    subtype 'MyCollectionsExtended'
+        => as 'ArrayRef|HashRef'
+        => where {
+            if (ref($_) eq 'ARRAY') {
+                return if scalar(@$_) < 2;
+            }
+            elsif (ref($_) eq 'HASH') {
+                return if scalar(keys(%$_)) < 2;
+            }
+            1;
+        };
+} '... created the subtype special okay';
+
+{
+    my $t = find_type_constraint('MyCollectionsExtended');
+    isa_ok($t, 'Mouse::Meta::TypeConstraint');
+
+    is($t->name, 'MyCollectionsExtended', '... name is correct');
+
+    my $p = $t->parent;
+#    isa_ok($p, 'Mouse::Meta::TypeConstraint::Union');
+    isa_ok($p, 'Mouse::Meta::TypeConstraint');
+
+    is($p->name, 'ArrayRef|HashRef', '... parent name is correct');
+
+    ok(!$t->check([]), '... validated it correctly');
+    ok($t->check([1, 2]), '... validated it correctly');
+
+    ok(!$t->check({}), '... validated it correctly');
+    ok($t->check({ one => 1, two => 2 }), '... validated it correctly');
+
+    ok(!$t->check(1), '... validated it correctly');
+}
+
+
diff --git a/t/900_bug/004_RT53286.t b/t/900_bug/004_RT53286.t
new file mode 100755 (executable)
index 0000000..b576f28
--- /dev/null
@@ -0,0 +1,66 @@
+#!perl -w
+# reported by Christine Spang (RT #53286)
+package Foo;
+use Mouse;
+
+has app_handle => (
+    is       => 'rw',
+    isa      => 'Baz',
+    required => 1,
+);
+
+has handle => (
+    is       => 'rw',
+    isa      => 'Int',
+    # app_handle should not be undef here!
+    default  => sub { shift->app_handle->handle() },
+);
+
+no Mouse;
+
+1;
+
+package Bar;
+use Mouse;
+
+has app_handle => (
+    is       => 'rw',
+    isa      => 'Baz',
+    required => 1,
+);
+
+sub do_something {
+    my $self = shift;
+    my $foo = Foo->new( app_handle => $self->app_handle );
+    return $foo->handle;
+}
+
+no Mouse;
+
+1;
+
+package Baz;
+use Mouse;
+
+sub handle {
+    # print "This works correctly.\n";
+    return 1;
+}
+
+no Mouse;
+
+1;
+
+package main;
+use strict;
+use warnings;
+use Test::More tests => 2;
+use Test::Exception;
+
+my $bar = Bar->new( app_handle => Baz->new() );
+ok($bar, "Test class Bar instantiated w/attribute app_handle Baz");
+
+# Trigger the default sub of baz's handle attribute, which tries to call
+# a method on an attribute which was set to an object passed in via the
+# constructor.
+lives_and { is($bar->do_something(), 1, "attribute was passed in okay") };
index b9aad70..2d26088 100644 (file)
@@ -388,7 +388,7 @@ mouse_instance_weaken_slot(pTHX_ SV* const instance, SV* const slot) {
         sv_rvweaken(HeVAL(he));
     }
 }
-\r
+
 MODULE = Mouse::Meta::Method::Accessor::XS  PACKAGE = Mouse::Meta::Method::Accessor::XS
 
 PROTOTYPES:   DISABLE