Revision history for Perl extension Moose
+0.45
+ * Moose::Meta::Method::Constructor
+ - fixed bug where trigger was not being
+ called by the inlined immutable
+ constructors
+ - added test for this (thanks to Caelum)
+
+ * Moose::Meta::Role::Application::ToInstance
+ - now uses the metaclass of the instance
+ (if possible) to create the anon-class
+ (thanks Jonathan Rockway)
+
+ * Moose::Cookbook::Snack::ArrayRef
+ Moose::Cookbook::Snack::HashRef
+ Moose::Cookbook::Snack::Perl5ObjsVsMooseObjs
+ Moose::Cookbook::Snack::BUILD
+ - several new Snacks added to the cookbook
+ (thanks to spicyjack)
+
+ * t/
+ - fixed hash-ordering test bug that was
+ causing occasional cpantester failures
+
0.44 Sat. May 10, 2008
* Moose
- made make_immutable warning cluck to
use strict;
use warnings;
-our $VERSION = '0.44';
+our $VERSION = '0.45';
our $AUTHORITY = 'cpan:STEVAN';
use Scalar::Util 'blessed', 'reftype';
else {
die('ERROR: file _' . $self->example_file . '_ does not exist');
}
- } # sub BUILD
+ }
package main;
use Moose;
=head2 What is 'BUILDALL'?
(Taken from L<Moose::Object>) The C<BUILDALL> method will call every BUILD
-method in the inheritance hierarchy, and pass it a hash-ref of the the %params
-passed to the C<new()> method.
+method in the inheritance hierarchy, and pass it a hash-ref of the the
+C<%params> passed to the C<new()> method.
=head1 SEE ALSO
=item L<Moose::Object> - The base object for Moose (BUILDALL)
-=item L<Moose::Cookbook::FAQ> - Frequently asked questions about Moose (How do I write custom constructors with Moose?)
+=item L<Moose::Cookbook::FAQ> - Frequently asked questions about Moose
+(How do I write custom constructors with Moose?)
-=item L<Moose::Cookbook::Recipe4> - Subtypes, and modeling a simple Company class heirarchy (Example usage of BUILD in action)
+=item L<Moose::Cookbook::Recipe4> - Subtypes, and modeling a simple
+Company class heirarchy (Example usage of BUILD in action)
-=item L<Moose::Cookbook::WTF> - For when things go wrong with Moose ('Roles' section describes BUILD/BUILDALL)
+=item L<Moose::Cookbook::WTF> - For when things go wrong with Moose
+('Roles' section describes BUILD/BUILDALL)
=back
=head1 COPYRIGHT AND LICENSE
-Copyright (c)2008 by Infinity Interactive, Inc.
+Copyright 2006-2008 by Infinity Interactive, Inc.
+
+L<http://www.iinteractive.com>
-This documentation is free software; you can redistribute it and/or modify
+This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
use Carp 'confess';
use Scalar::Util 'blessed', 'weaken', 'looks_like_number';
-our $VERSION = '0.09';
+our $VERSION = '0.10';
our $AUTHORITY = 'cpan:STEVAN';
use base 'Moose::Meta::Method',
$self->_generate_slot_initializer($_)
} 0 .. (@{$self->attributes} - 1));
+ $source .= ";\n" . $self->_generate_triggers();
$source .= ";\n" . $self->_generate_BUILDALL();
$source .= ";\n" . 'return $instance';
return join ";\n" => @BUILD_calls;
}
+sub _generate_triggers {
+ my $self = shift;
+ my @trigger_calls;
+ foreach my $i (0 .. $#{ $self->attributes }) {
+ my $attr = $self->attributes->[$i];
+ if ($attr->can('has_trigger') && $attr->has_trigger) {
+ if (defined(my $init_arg = $attr->init_arg)) {
+ push @trigger_calls => (
+ '(exists $params{\'' . $init_arg . '\'}) && do {' . "\n "
+ . '$attrs->[' . $i . ']->trigger->('
+ . '$instance, '
+ . $self->meta_instance->inline_get_slot_value(
+ '$instance',
+ ("'" . $attr->name . "'")
+ )
+ . ', '
+ . '$attrs->[' . $i . ']'
+ . ');'
+ ."\n}"
+ );
+ }
+ }
+ }
+ return join ";\n" => @trigger_calls;
+}
+
sub _generate_slot_initializer {
my $self = shift;
my $index = shift;
use Carp 'confess';
use Scalar::Util 'blessed';
-our $VERSION = '0.02';
+our $VERSION = '0.03';
our $AUTHORITY = 'cpan:STEVAN';
use base 'Moose::Meta::Role::Application::ToClass';
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+use Test::Exception;
+
+BEGIN {
+ use_ok('Moose');
+}
+
+{
+ package AClass;
+
+ use Moose;
+
+ has 'foo' => (is => 'rw', isa => 'Maybe[Str]', trigger => sub {
+ die "Pulling the Foo trigger\n"
+ });
+
+ has 'bar' => (is => 'rw', isa => 'Maybe[Str]');
+
+ has 'baz' => (is => 'rw', isa => 'Maybe[Str]', trigger => sub {
+ die "Pulling the Baz trigger\n"
+ });
+
+ __PACKAGE__->meta->make_immutable; #(debug => 1);
+
+ no Moose;
+}
+
+eval { AClass->new(foo => 'bar') };
+like ($@, qr/^Pulling the Foo trigger/, "trigger from immutable constructor");
+
+eval { AClass->new(baz => 'bar') };
+like ($@, qr/^Pulling the Baz trigger/, "trigger from immutable constructor");
+
+lives_ok { AClass->new(bar => 'bar') } '... no triggers called';
+
+
+