From: Stevan Little Date: Wed, 15 Mar 2006 23:42:45 +0000 (+0000) Subject: 0.01 X-Git-Tag: 0_05~101 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e522431d8d7dfeffe645a28a045fa85fae03c8f0;p=gitmo%2FMoose.git 0.01 --- diff --git a/Build.PL b/Build.PL index d2ad178..d9c09bb 100644 --- a/Build.PL +++ b/Build.PL @@ -7,8 +7,8 @@ my $build = Module::Build->new( license => 'perl', requires => { 'Scalar::Util' => '1.18', - 'Carp' => '0.01', - 'Class::MOP' => '0.20', + 'Carp' => '0', + 'Class::MOP' => '0.21', 'Sub::Name' => '0.02', }, optional => { diff --git a/Changes b/Changes new file mode 100644 index 0000000..fe98b30 --- /dev/null +++ b/Changes @@ -0,0 +1,4 @@ +Revision history for Perl extension Moose + +0.01 Wed. March 15, 2006 + - Moooooooooooooooooose!!! \ No newline at end of file diff --git a/MANIFEST b/MANIFEST index e69de29..4b051e5 100644 --- a/MANIFEST +++ b/MANIFEST @@ -0,0 +1,23 @@ +Build.PL +Changes +Makefile.PL +META.yml +MANIFEST +MANIFEST.SKIP +README +lib/Moose.pm +lib/Moose/Object.pm +lib/Moose/Meta/Attribute.pm +lib/Moose/Meta/Class.pm +lib/Moose/Util/TypeConstraints.pm +t/000_load.t +t/001_basic.t +t/002_basic.t +t/003_basic.t +t/010_basic_class_setup.t +t/020_foreign_inheritence.t +t/050_util_type_constraints.t +t/051_util_type_constraints_export.t +t/052_util_std_type_constraints.t +t/pod.t +t/pod_coverage.t diff --git a/lib/Moose.pm b/lib/Moose.pm index 735c2d8..dcec72a 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -1,6 +1,4 @@ -use lib '/Users/stevan/CPAN/Class-MOP/Class-MOP/lib'; - package Moose; use strict; @@ -33,7 +31,13 @@ sub import { else { $meta = Moose::Meta::Class->initialize($pkg => ( ':attribute_metaclass' => 'Moose::Meta::Attribute' - )); + )); + $meta->add_method('meta' => sub { + # re-initialize so it inherits properly + Moose::Meta::Class->initialize($pkg => ( + ':attribute_metaclass' => 'Moose::Meta::Attribute' + )); + }) } # NOTE: @@ -99,17 +103,71 @@ __END__ =head1 NAME -Moose - +Moose - Moose, it's the new Camel =head1 SYNOPSIS + + package Point; + use Moose; + + has 'x' => (isa => Int(), is => 'rw'); + has 'y' => (isa => Int(), is => 'rw'); + + sub clear { + my $self = shift; + $self->x(0); + $self->y(0); + } + + package Point3D; + use Moose; + + extends 'Point'; + has 'z' => (isa => Int()); + + after 'clear' => sub { + my $self = shift; + $self->{z} = 0; + }; + +=head1 CAVEAT + +This is a B early release of this module, it still needs +some fine tuning and B more documentation. I am adopting +the I approach with this module, +so keep an eye on your favorite CPAN mirror! + =head1 DESCRIPTION -=head1 OTHER NAMES +Moose is an extension of the Perl 5 object system. + +=head2 Another object system!?!? -Makes Other Object Systems Envious +Yes, I know there has been an explosion recently of new ways to +build object's in Perl 5, most of them based on inside-out objects, +and other such things. Moose is different because it is not a new +object system for Perl 5, but instead an extension of the existing +object system. -Makes Object Orientation So Easy +Moose is built on top of L, which is a metaclass system +for Perl 5. This means that Moose not only makes building normal +Perl 5 objects better, but is also provides brings with it the power +of metaclass programming. + +=head2 What does Moose stand for?? + +Moose doesn't stand for one thing in particular, however, if you +want, here are a few of my favorites, feel free to contribute +more :) + +=over 4 + +=item Makes Other Object Systems Envious + +=item Makes Object Orientation So Easy + +=back =head1 BUGS @@ -117,13 +175,6 @@ All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. -=head1 CODE COVERAGE - -I use L to test the code coverage of my tests, below is the -L report on this module's test suite. - -=head1 ACKNOWLEDGEMENTS - =head1 AUTHOR Stevan Little Estevan@iinteractive.comE diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 464aa66..2d59ce1 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -124,12 +124,15 @@ __END__ =head1 NAME -Moose::Meta::Attribute - +Moose::Meta::Attribute - The Moose attribute metaobject =head1 SYNOPSIS =head1 DESCRIPTION +This is a subclass of L with Moose specific +extensions. + =head1 METHODS =over 4 @@ -160,13 +163,6 @@ All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. -=head1 CODE COVERAGE - -I use L to test the code coverage of my tests, below is the -L report on this module's test suite. - -=head1 ACKNOWLEDGEMENTS - =head1 AUTHOR Stevan Little Estevan@iinteractive.comE diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 81c0740..76fcbea 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -12,7 +12,7 @@ use base 'Class::MOP::Class'; sub construct_instance { my ($class, %params) = @_; - my $instance = {}; + my $instance = $params{'__INSTANCE__'} || {}; foreach my $attr ($class->compute_all_applicable_attributes()) { my $init_arg = $attr->init_arg(); # try to fetch the init arg from the %params ... @@ -38,12 +38,15 @@ __END__ =head1 NAME -Moose::Meta::Class - +Moose::Meta::Class - The Moose metaclass =head1 SYNOPSIS =head1 DESCRIPTION +This is a subclass of L with Moose specific +extensions. + =head1 METHODS =over 4 @@ -58,13 +61,6 @@ All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. -=head1 CODE COVERAGE - -I use L to test the code coverage of my tests, below is the -L report on this module's test suite. - -=head1 ACKNOWLEDGEMENTS - =head1 AUTHOR Stevan Little Estevan@iinteractive.comE diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 5d4de68..3639c56 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -42,9 +42,9 @@ __END__ =head1 NAME -Moose::Object - +Moose::Object - The base object for Moose -=head1 SYNOPSIS +=head1 SYNOPSIS =head1 DESCRIPTION @@ -56,10 +56,16 @@ Moose::Object - =item B +This will create a new instance and call C. + =item B +This will call every C method in the inheritance hierarchy. + =item B +This will call every C method in the inheritance hierarchy. + =back =head1 BUGS @@ -68,13 +74,6 @@ All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. -=head1 CODE COVERAGE - -I use L to test the code coverage of my tests, below is the -L report on this module's test suite. - -=head1 ACKNOWLEDGEMENTS - =head1 AUTHOR Stevan Little Estevan@iinteractive.comE diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index e973f23..1461848 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -107,7 +107,7 @@ __END__ =head1 NAME -Moose::Util::TypeConstraints - +Moose::Util::TypeConstraints - Type constraint system for Moose =head1 SYNOPSIS @@ -125,6 +125,33 @@ Moose::Util::TypeConstraints - =head1 DESCRIPTION +This module provides Moose with the ability to create type contraints +to be are used in both attribute definitions and for method argument +validation. + +This is B a type system for Perl 5. + +The type and subtype constraints are basically functions which will +validate their first argument. If called with no arguments, they will +return themselves (this is syntactic sugar for Moose attributes). + +This module also provides a simple hierarchy for Perl 5 types, this +could probably use some work, but it works for me at the moment. + + Any + Value + Int + Str + Ref + ScalarRef + ArrayRef + HashRef + CodeRef + RegexpRef + Object + +Suggestions for improvement are welcome. + =head1 FUNCTIONS =head2 Type Constraint Constructors @@ -175,13 +202,6 @@ All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. -=head1 CODE COVERAGE - -I use L to test the code coverage of my tests, below is the -L report on this module's test suite. - -=head1 ACKNOWLEDGEMENTS - =head1 AUTHOR Stevan Little Estevan@iinteractive.comE diff --git a/t/001_basic.t b/t/001_basic.t index e2b893b..8f8acb9 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 41; +use Test::More tests => 43; use Test::Exception; BEGIN { @@ -127,7 +127,7 @@ is_deeply( [ 'Moose::Object' ], '... Point got the automagic base class'); -my @Point_methods = qw(x y clear); +my @Point_methods = qw(meta x y clear); my @Point_attrs = ('x', 'y'); is_deeply( @@ -151,7 +151,7 @@ is_deeply( [ 'Point' ], '... Point3D gets the parent given to it'); -my @Point3D_methods = qw(clear); +my @Point3D_methods = qw(meta clear); my @Point3D_attrs = ('z'); is_deeply( diff --git a/t/010_basic_class_setup.t b/t/010_basic_class_setup.t index e5fe63d..be71ec3 100644 --- a/t/010_basic_class_setup.t +++ b/t/010_basic_class_setup.t @@ -18,7 +18,7 @@ BEGIN { can_ok('Foo', 'meta'); isa_ok(Foo->meta, 'Moose::Meta::Class'); -ok(!Foo->meta->has_method('meta'), '... we get the &meta method from Moose::Object'); +ok(Foo->meta->has_method('meta'), '... we got the &meta method'); ok(Foo->isa('Moose::Object'), '... Foo is automagically a Moose::Object'); foreach my $function (qw( diff --git a/t/020_foreign_inheritence.t b/t/020_foreign_inheritence.t new file mode 100644 index 0000000..b9b8372 --- /dev/null +++ b/t/020_foreign_inheritence.t @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 5; +use Test::Exception; + +BEGIN { + use_ok('Moose'); +} + +{ + package Elk; + use strict; + use warnings; + + sub new { + my $class = shift; + bless { no_moose => "Elk" } => $class; + } + + sub no_moose { $_[0]->{no_moose} } + + package Foo::Moose; + use strict; + use warnings; + use Moose; + + extends 'Elk'; + + has 'moose' => (is => 'ro', default => 'Foo'); + + sub new { + my $class = shift; + my $super = $class->SUPER::new(@_); + return $class->meta->new_object('__INSTANCE__' => $super, @_); + } +} + +my $foo_moose = Foo::Moose->new(); +isa_ok($foo_moose, 'Foo::Moose'); +isa_ok($foo_moose, 'Elk'); + +is($foo_moose->no_moose, 'Elk', '... got the right value from the Elk method'); +is($foo_moose->moose, 'Foo', '... got the right value from the Foo::Moose method'); \ No newline at end of file