From: Stevan Little Date: Mon, 27 Nov 2006 01:58:08 +0000 (+0000) Subject: foo X-Git-Tag: 0_18~2^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=587ae0d2067068a8ad38926a4f4104aba21270f4;p=gitmo%2FMoose.git foo --- diff --git a/Changes b/Changes index d28bc9f..79c5c1d 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,34 @@ Revision history for Perl extension Moose +0.18_001 + +0.17 Tues. Nov. 14, 2006 + * Moose::Meta::Method::Accessor + - bugfix for read-only accessors which + are have a type constraint and lazy. + Thanks to chansen for finding it. + +0.16 Tues. Nov. 14, 2006 + ++ NOTE ++ + There are some speed improvements in this release, + but they are only the begining, so stay tuned. + + * Moose::Object + - BUILDALL and DEMOLISHALL no longer get + called unless they actually need to be. + This gave us a signifigant speed boost + for the cases when there is no BUILD or + DEMOLISH method present. + + * Moose::Util::TypeConstraints + * Moose::Meta::TypeConstraint + - added an 'optimize_as' option to the + type constraint, which allows for a + hand optimized version of the type + constraint to be used when possible. + - Any internally created type constraints + now provide an optimized version as well. + 0.15 Sun. Nov. 5, 2006 ++ NOTE ++ This version of Moose *must* have Class::MOP 0.36 in order diff --git a/MANIFEST b/MANIFEST index a0ba448..c91742a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,7 +1,7 @@ Build.PL Changes -META.yml Makefile.PL +META.yml MANIFEST MANIFEST.SKIP README @@ -25,6 +25,8 @@ lib/Moose/Meta/Role.pm lib/Moose/Meta/TypeCoercion.pm lib/Moose/Meta/TypeConstraint.pm lib/Moose/Meta/Method/Accessor.pm +lib/Moose/Meta/Method/Constructor.pm +lib/Moose/Meta/Method/Destructor.pm lib/Moose/Meta/Method/Overriden.pm lib/Moose/Meta/Role/Method.pm lib/Moose/Meta/TypeConstraint/Union.pm @@ -87,6 +89,7 @@ t/100_subtype_quote_bug.t t/101_subtype_conflict_bug.t t/102_Moose_Object_error.t t/103_subclass_use_base_bug.t +t/104_inline_reader_bug.t t/201_example.t t/202_example_Moose_POOP.t t/203_example.t diff --git a/README b/README index 1696dfc..9cc6fba 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Moose version 0.15 +Moose version 0.17 =========================== See the individual module documentation for more information diff --git a/TODO b/TODO index 4d90ee8..38386c1 100644 --- a/TODO +++ b/TODO @@ -8,6 +8,19 @@ mst: if I do "subtype 'Foo' => as 'Bar';" I get an empty condition and it dies TODO ------------------------------------------------------------------------------- +- DDuncan's Str types + +subtype 'Str' + => as 'Value' + => where { Encode::is_utf8( $_[0] ) or $_[0] !~ m/[^0x00-0x7F]/x } + => optimize_as { defined($_[0]) && !ref($_[0]) }; + +subtype 'Blob' + => as 'Value' + => where { !Encode::is_utf8( $_[0] ) } + => optimize_as { defined($_[0]) && !ref($_[0]) }; + + - should handle some moose-specific options in &Moose::Meta::Class::create things like roles, and method modifiers (although those can probably be ignored if i want to) diff --git a/benchmarks/caf_vs_moose.pl b/benchmarks/caf_vs_moose.pl new file mode 100644 index 0000000..55a3e0f --- /dev/null +++ b/benchmarks/caf_vs_moose.pl @@ -0,0 +1,91 @@ +#!perl + +### MODULES + +package MooseHorse; +use Moose; +has foo => (is => 'rw'); +no Moose; + +package MooseHorseImmut; +use Moose; +has foo => (is => 'rw'); +__PACKAGE__->meta->make_immutable(); +no Moose; + +package MooseHorseImmutNoConst; +use Moose; +has foo => (is => 'rw'); +__PACKAGE__->meta->make_immutable(inline_constructor => 0); +no Moose; + + +package CAFHorse; +use warnings; +use strict; +use base 'Class::Accessor::Fast'; +__PACKAGE__->mk_accessors(qw(foo)); + + +package main; +use warnings; +use strict; + +use Benchmark qw(cmpthese); +use Benchmark ':hireswallclock'; + +my $moose = MooseHorse->new; +my $moose_immut = MooseHorseImmut->new; +my $moose_immut_no_const = MooseHorseImmutNoConst->new; +my $caf = CAFHorse->new; + +my $acc_rounds = 1_000_000; +my $ins_rounds = 1_000_000; + +print "\nSETTING\n"; +cmpthese($acc_rounds, { + Moose => sub { $moose->foo(23) }, + MooseImmut => sub { $moose_immut->foo(23) }, + MooseImmutNoConst => sub { $moose_immut_no_const->foo(23) }, + CAF => sub { $caf->foo(23) }, +}, 'noc'); + +print "\nGETTING\n"; +cmpthese($acc_rounds, { + Moose => sub { $moose->foo }, + MooseImmut => sub { $moose_immut->foo }, + MooseImmutNoConst => sub { $moose_immut_no_const->foo }, + CAF => sub { $caf->foo }, +}, 'noc'); + +my (@moose, @moose_immut, @moose_immut_no_const, @caf_stall); +print "\nCREATION\n"; +cmpthese($ins_rounds, { + Moose => sub { push @moose, MooseHorse->new(foo => 23) }, + MooseImmut => sub { push @moose_immut, MooseHorseImmut->new(foo => 23) }, + MooseImmutNoConst => sub { push @moose_immut_no_const, MooseHorseImmutNoConst->new(foo => 23) }, + CAF => sub { push @caf_stall, CAFHorse->new({foo => 23}) }, +}, 'noc'); + +my ( $moose_idx, $moose_immut_idx, $moose_immut_no_const_idx, $caf_idx ) = ( 0, 0, 0, 0 ); +print "\nDESTRUCTION\n"; +cmpthese($ins_rounds, { + Moose => sub { + $moose[$moose_idx] = undef; + $moose_idx++; + }, + MooseImmut => sub { + $moose_immut[$moose_immut_idx] = undef; + $moose_immut_idx++; + }, + MooseImmutNoConst => sub { + $moose_immut_no_const[$moose_immut_no_const_idx] = undef; + $moose_immut_no_const_idx++; + }, + CAF => sub { + $caf_stall[$caf_idx] = undef; + $caf_idx++; + }, +}, 'noc'); + + diff --git a/benchmarks/simple_constructor.pl b/benchmarks/simple_constructor.pl new file mode 100644 index 0000000..66c0ac3 --- /dev/null +++ b/benchmarks/simple_constructor.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +my $num_iterations = shift || 100; + +{ + package Foo; + use Moose; + + has 'default' => (is => 'rw', default => 10); + has 'default_sub' => (is => 'rw', default => sub { [] }); + has 'lazy' => (is => 'rw', default => 10, lazy => 1); + has 'required' => (is => 'rw', required => 1); + has 'weak_ref' => (is => 'rw', weak_ref => 1); + has 'type_constraint' => (is => 'rw', isa => 'ArrayRef'); +} + +foreach (0 .. $num_iterations) { + my $foo = Foo->new( + required => 'BAR', + type_constraint => [], + weak_ref => {}, + ); +} \ No newline at end of file diff --git a/benchmarks/type_constraints.pl b/benchmarks/type_constraints.pl index 2e87d83..8af49ef 100644 --- a/benchmarks/type_constraints.pl +++ b/benchmarks/type_constraints.pl @@ -20,7 +20,6 @@ all vs. a custom-created type. has 'baz' => (is => 'rw'); has 'bar' => (is => 'rw', isa => 'Foo'); - #has 'boo' => (is => 'rw', isa => type 'CustomFoo' => where { blessed($_) && $_->isa('Foo') }); } { @@ -47,10 +46,7 @@ cmpthese(200_000, }, 'w_constraint' => sub { $foo->bar($foo); - }, - #'w_custom_constraint' => sub { - # $foo->boo($foo); - #}, + }, } ); diff --git a/lib/Moose.pm b/lib/Moose.pm index 632ec6c..a850406 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -1,12 +1,10 @@ -use lib '/Users/stevan/Projects/Moose/Moose/Class-MOP/branches/Class-MOP-tranformations/lib'; - package Moose; use strict; use warnings; -our $VERSION = '0.15'; +our $VERSION = '0.18_001'; use Scalar::Util 'blessed', 'reftype'; use Carp 'confess'; diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index ac40807..5d3d8b4 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -9,7 +9,7 @@ use Class::MOP; use Carp 'confess'; use Scalar::Util 'weaken', 'blessed', 'reftype'; -our $VERSION = '0.08'; +our $VERSION = '0.09'; use Moose::Meta::Method::Overriden; diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index 1934a50..4fe682c 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -6,7 +6,7 @@ use warnings; use Carp 'confess'; -our $VERSION = '0.01'; +our $VERSION = '0.03'; use base 'Moose::Meta::Method', 'Class::MOP::Method::Accessor'; @@ -97,8 +97,6 @@ sub generate_reader_method_inline { *generate_writer_method = \&generate_writer_method_inline; *generate_accessor_method = \&generate_accessor_method_inline; -## ... private helpers - sub _inline_check_constraint { my ($self, $value) = @_; diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 3f7bfe6..6cd6eb7 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -18,24 +18,14 @@ sub new { (exists $options{options} && ref $options{options} eq 'HASH') || confess "You must pass a hash of options"; - - (blessed $options{meta_instance} && $options{meta_instance}->isa('Class::MOP::Instance')) - || confess "You must supply a meta-instance"; - - (exists $options{attributes} && ref $options{attributes} eq 'ARRAY') - || confess "You must pass an array of options"; - - (blessed($_) && $_->isa('Class::MOP::Attribute')) - || confess "You must supply a list of attributes which is a 'Class::MOP::Attribute' instance" - for @{$options{attributes}}; my $self = bless { # from our superclass '&!body' => undef, # specific to this subclass '%!options' => $options{options}, - '$!meta_instance' => $options{meta_instance}, - '@!attributes' => $options{attributes}, + '$!meta_instance' => $options{metaclass}->get_meta_instance, + '@!attributes' => [ $options{metaclass}->compute_all_applicable_attributes ], # ... '$!associated_metaclass' => $options{metaclass}, } => $class; @@ -43,7 +33,7 @@ sub new { # we don't want this creating # a cycle in the code, if not # needed - weaken($self->{'$!meta_instance'}); +# weaken($self->{'$!meta_instance'}); weaken($self->{'$!associated_metaclass'}); $self->intialize_body; @@ -73,7 +63,7 @@ sub intialize_body { my $source = 'sub {'; $source .= "\n" . 'my $class = shift;'; - $source .= "\n" . 'return $class->Moose::Object::' . $self->options->{constructor_name} . '(@_)'; + $source .= "\n" . 'return $class->Moose::Object::new(@_)'; $source .= "\n" . ' if $class ne \'' . $self->associated_metaclass->name . '\';'; $source .= "\n" . 'my %params = (scalar @_ == 1) ? %{$_[0]} : @_;'; diff --git a/lib/Moose/Meta/Method/Destructor.pm b/lib/Moose/Meta/Method/Destructor.pm index e273361..efbf12c 100644 --- a/lib/Moose/Meta/Method/Destructor.pm +++ b/lib/Moose/Meta/Method/Destructor.pm @@ -82,4 +82,46 @@ __END__ =pod -=cut \ No newline at end of file +=head1 NAME + +Moose::Meta::Method::Destructor - Method Meta Object for destructors + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +=head1 METHODS + +=over 4 + +=item B + +=item B + +=item B + +=item B + +=item B + +=item B + +=item B + +=back + +=head1 AUTHORS + +Stevan Little Estevan@iinteractive.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index fb85f4c..518cd29 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -9,7 +9,7 @@ use Sub::Name 'subname'; use Carp 'confess'; use Scalar::Util 'blessed'; -our $VERSION = '0.06'; +our $VERSION = '0.07'; use Moose::Meta::TypeConstraint::Union; @@ -254,4 +254,4 @@ L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut \ No newline at end of file +=cut diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index af7dc87..276a973 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -1,6 +1,4 @@ -use lib '/Users/stevan/Projects/Moose/Moose/Class-MOP/branches/Class-MOP-tranformations/lib'; - package Moose::Role; use strict; diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 655894d..636ba2f 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -1,6 +1,4 @@ -use lib '/Users/stevan/Projects/Moose/Moose/Class-MOP/branches/Class-MOP-tranformations/lib'; - package Moose::Util::TypeConstraints; use strict; @@ -11,7 +9,7 @@ use Scalar::Util 'blessed'; use B 'svref_2object'; use Sub::Exporter; -our $VERSION = '0.09'; +our $VERSION = '0.10'; use Moose::Meta::TypeConstraint; use Moose::Meta::TypeCoercion; @@ -71,7 +69,7 @@ sub unimport { $message = $_->{message} if exists $_->{message}; $optimized = $_->{optimized} if exists $_->{optimized}; } - + my $pkg_defined_in = scalar(caller(1)); ($TYPES{$name}->[0] eq $pkg_defined_in) || confess "The type constraint '$name' has already been created " @@ -395,11 +393,11 @@ This is just sugar for the type constraint construction syntax. =head2 Type Coercion Constructors -Type constraints can also contain type coercions as well. In most -cases Moose will run the type-coercion code first, followed by the -type constraint check. This feature should be used carefully as it -is very powerful and could easily take off a limb if you are not -careful. +Type constraints can also contain type coercions as well. If you +ask your accessor too coerce, the Moose will run the type-coercion +code first, followed by the type constraint check. This feature +should be used carefully as it is very powerful and could easily +take off a limb if you are not careful. See the L for an example of how to use these. diff --git a/t/001_recipe.t b/t/001_recipe.t index 771a795..91b877a 100644 --- a/t/001_recipe.t +++ b/t/001_recipe.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 58; +use Test::More tests => 60; use Test::Exception; BEGIN { @@ -128,7 +128,7 @@ is_deeply( [ 'Moose::Object' ], '... Point got the automagic base class'); -my @Point_methods = qw(meta new x y clear); +my @Point_methods = qw(meta new x y clear DESTROY); my @Point_attrs = ('x', 'y'); is_deeply( @@ -160,7 +160,7 @@ is_deeply( [ 'Point' ], '... Point3D gets the parent given to it'); -my @Point3D_methods = qw(new meta clear); +my @Point3D_methods = qw(new meta clear DESTROY); my @Point3D_attrs = ('z'); is_deeply( diff --git a/t/104_inline_reader_bug.t b/t/104_inline_reader_bug.t new file mode 100644 index 0000000..7321764 --- /dev/null +++ b/t/104_inline_reader_bug.t @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; +use Test::Exception; + +BEGIN { + use_ok('Moose'); +} + +=pod + +This was a bug, but it is fixed now. This +test makes sure it does not creep back in. + +=cut + +{ + package Foo; + use Moose; + + ::lives_ok { + has 'bar' => ( + is => 'ro', + isa => 'Int', + lazy => 1, + default => 10, + ); + } '... this didnt die'; +} +