From: Stevan Little Date: Thu, 16 Mar 2006 21:50:50 +0000 (+0000) Subject: mixins X-Git-Tag: 0_05~99 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b6aed8b0f308d960417e72e2baca1c34cac515b6;p=gitmo%2FMoose.git mixins --- diff --git a/lib/Moose.pm b/lib/Moose.pm index df54342..bda04b7 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -4,7 +4,7 @@ package Moose; use strict; use warnings; -our $VERSION = '0.01'; +our $VERSION = '0.02'; use Scalar::Util 'blessed', 'reftype'; use Carp 'confess'; diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index adf7cc6..68db685 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -3,12 +3,13 @@ package Moose::Object; use strict; use warnings; - use metaclass 'Moose::Meta::Class' => ( ':attribute_metaclass' => 'Moose::Meta::Attribute' ); -our $VERSION = '0.01'; +use Carp 'confess'; + +our $VERSION = '0.02'; sub new { my $class = shift; @@ -32,15 +33,6 @@ sub DEMOLISHALL { } } -sub NEXT { - my $self = shift; - my $method = (caller())[3]; - my $code = $self->meta->find_next_method_by_name($method); - (defined $code) - || confess "Could not find the NEXT method for ($method) in ($self)"; - return $code->($self, @_); -} - sub DESTROY { goto &DEMOLISHALL } 1; @@ -75,6 +67,8 @@ This will call every C method in the inheritance hierarchy. This will call every C method in the inheritance hierarchy. +=item B + =back =head1 BUGS diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 1461848..a9a6b52 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -34,7 +34,6 @@ sub import { my %TYPES; -# might need this later #sub find_type_constraint { $TYPES{$_[0]} } sub type ($$) { diff --git a/t/031_mixin_example.t b/t/031_mixin_example.t index 0ac4883..5651086 100644 --- a/t/031_mixin_example.t +++ b/t/031_mixin_example.t @@ -3,7 +3,8 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 5; +use SUPER; BEGIN { use_ok('Moose'); @@ -13,11 +14,7 @@ BEGIN { This test demonstrates how simple it is to create Scala Style Class Mixin Composition. Below is an example taken from the -Scala web site's example section, and trancoded to Class::MOP. - -NOTE: -We require SUPER for this test to handle the issue with SUPER:: -being determined at compile time. +Scala web site's example section, and trancoded to Moose. L @@ -57,58 +54,45 @@ code above is well-formed. { package Point2D; - use metaclass; - - Point2D->meta->add_attribute('$x' => ( - accessor => 'x', - init_arg => 'x', - )); - - Point2D->meta->add_attribute('$y' => ( - accessor => 'y', - init_arg => 'y', - )); + use Moose; - sub new { - my $class = shift; - $class->meta->new_object(@_); - } + has 'x' => (is => 'rw'); + has 'y' => (is => 'rw'); - sub toString { + sub to_string { my $self = shift; "x = " . $self->x . ", y = " . $self->y; } package ColoredPoint2D; - our @ISA = ('Point2D'); + use Moose; - ColoredPoint2D->meta->add_attribute('$color' => ( - accessor => 'color', - init_arg => 'color', - )); + extends 'Point2D'; - sub toString { + has 'color' => (is => 'rw'); + + sub to_string { my $self = shift; $self->SUPER() . ', col = ' . $self->color; } package Point3D; - our @ISA = ('Point2D'); + use Moose; + + extends 'Point2D'; - Point3D->meta->add_attribute('$z' => ( - accessor => 'z', - init_arg => 'z', - )); + has 'z' => (is => 'rw'); - sub toString { + sub to_string { my $self = shift; $self->SUPER() . ', z = ' . $self->z; } package ColoredPoint3D; - our @ISA = ('Point3D'); + use Moose; - ::with('ColoredPoint2D'); + extends 'Point3D'; + with 'ColoredPoint2D'; } @@ -117,7 +101,7 @@ isa_ok($colored_point_3d, 'ColoredPoint3D'); isa_ok($colored_point_3d, 'Point3D'); isa_ok($colored_point_3d, 'Point2D'); -is($colored_point_3d->toString(), +is($colored_point_3d->to_string(), 'x = 1, y = 2, z = 3, col = blue', '... got the right toString method');