* Moose::Meta::Method::Accessor
Moose::Meta::Method::Constructor
- Moose::Meta::Method::Attribute
- - cleanup of some of the generated methods
- (thanks to nothingmuch)
+ Moose::Meta::Attribute
+ Moose::Meta::TypeConstraint
+ Moose::Meta::TypeCoercion
+ - lots of cleanup of such things as:
+ - generated methods
+ - type constraint handling
+ - error handling/messages
+ (thanks to nothingmuch)
* Moose::Util::TypeConstraints
- all optimized type constraint subs are now
# prereqs
requires 'Scalar::Util' => $win32 ? '1.17' : '1.18';
requires 'Carp';
-requires 'Class::MOP' => '0.49';
+requires 'Class::MOP' => '0.51';
requires 'Sub::Name' => '0.02';
requires 'Sub::Exporter' => '0.972';
use Sub::Name 'subname';
use overload ();
-our $VERSION = '0.17';
+our $VERSION = '0.18';
our $AUTHORITY = 'cpan:STEVAN';
use Moose::Meta::Method::Accessor;
$associated_class->add_method($handle => subname $name, sub {
my $proxy = (shift)->$accessor();
@_ = ($proxy, @_);
+ (defined $proxy)
+ || confess "Cannot delegate $handle to $method_to_call because " .
+ "the value of " . $self->name . " is not defined";
goto &{ $proxy->can($method_to_call) || return };
});
}
use Carp 'confess';
-our $VERSION = '0.10';
+our $VERSION = '0.11';
our $AUTHORITY = 'cpan:STEVAN';
use base 'Moose::Meta::Method',
use Carp 'confess';
use Scalar::Util 'blessed', 'weaken', 'looks_like_number';
-our $VERSION = '0.04';
+our $VERSION = '0.05';
our $AUTHORITY = 'cpan:STEVAN';
use base 'Moose::Meta::Method',
require Moose::Meta::Role::Application::RoleSummation;
require Moose::Meta::Role::Composite;
- my @roles = map { $_->[0]->meta } @role_specs;
-
- my %params;
- # how do I do this ...
+ my (@roles, %role_params);
+ while (@role_specs) {
+ my ($role, $params) = @{ splice @role_specs, 0, 1 };
+ push @roles => $role->meta;
+ next unless defined $params;
+ $role_params{$role} = $params;
+ }
my $c = Moose::Meta::Role::Composite->new(roles => \@roles);
Moose::Meta::Role::Application::RoleSummation->new(
- %params
+ role_params => \%role_params
)->apply($c);
+
return $c;
}
use base 'Moose::Meta::Role::Application';
+__PACKAGE__->meta->add_attribute('role_params' => (
+ reader => 'role_params',
+ default => sub { {} }
+));
+
+sub get_exclusions_for_role {
+ my ($self, $role) = @_;
+ $role = $role->name if blessed $role;
+ if ($self->role_params->{$role} && defined $self->role_params->{$role}->{excludes}) {
+ if (ref $self->role_params->{$role}->{excludes} eq 'ARRAY') {
+ return $self->role_params->{$role}->{excludes};
+ }
+ return [ $self->role_params->{$role}->{excludes} ];
+ }
+ return [];
+}
+
+sub get_method_aliases_for_role {
+ my ($self, $role) = @_;
+ $role = $role->name if blessed $role;
+ if ($self->role_params->{$role} && defined $self->role_params->{$role}->{alias}) {
+ return $self->role_params->{$role}->{alias};
+ }
+ return {};
+}
+
+sub is_method_excluded {
+ my ($self, $role, $method_name) = @_;
+ foreach ($self->get_exclusions_for_role($role->name)) {
+ return 1 if $_ eq $method_name;
+ }
+ return 0;
+}
+
+sub is_method_aliased {
+ my ($self, $role, $method_name) = @_;
+ exists $self->get_method_aliases_for_role($role->name)->{$method_name} ? 1 : 0
+}
+
+sub is_aliased_method {
+ my ($self, $role, $method_name) = @_;
+ my %aliased_names = reverse %{$self->get_method_aliases_for_role($role->name)};
+ exists $aliased_names{$method_name} ? 1 : 0;
+}
+
# stolen from List::MoreUtils ...
my $uniq = sub { my %h; map { $h{$_}++ == 0 ? $_ : () } @_ };
foreach my $role (@{$c->get_roles}) {
foreach my $required (keys %all_required_methods) {
+
delete $all_required_methods{$required}
- if $role->has_method($required);
+ if $role->has_method($required)
+ || $self->is_aliased_method($role, $required);
}
}
my ($self, $c) = @_;
my @all_methods = map {
- my $role = $_;
- map {
- +{
- name => $_,
- method => $role->get_method($_),
- }
- } $role->get_method_list;
+ my $role = $_;
+ my $aliases = $self->get_method_aliases_for_role($role);
+ my %excludes = map { $_ => undef } @{ $self->get_exclusions_for_role($role) };
+ (
+ (map {
+ exists $excludes{$_} ? () :
+ +{
+ role => $role,
+ name => $_,
+ method => $role->get_method($_),
+ }
+ } $role->get_method_list),
+ (map {
+ +{
+ role => $role,
+ name => $aliases->{$_},
+ method => $role->get_method($_),
+ }
+ } keys %$aliases)
+ );
} @{$c->get_roles};
my (%seen, %method_map);
delete $method_map{$method->{name}};
next;
}
- }
+ }
+
$seen{$method->{name}} = $method->{method};
$method_map{$method->{name}} = $method->{method};
}
=item B<meta>
+=item B<role_params>
+
+=item B<get_exclusions_for_role>
+
+=item B<get_method_aliases_for_role>
+
+=item B<is_aliased_method>
+
+=item B<is_method_aliased>
+
+=item B<is_method_excluded>
+
=item B<apply>
=item B<check_role_exclusions>
use warnings;
use metaclass;
-use Carp 'confess';
-use Scalar::Util 'blessed', 'reftype';
-
-use Data::Dumper;
+use Carp 'confess';
+use Scalar::Util 'blessed', 'reftype';
our $VERSION = '0.01';
our $AUTHORITY = 'cpan:STEVAN';
use Moose::Meta::Attribute;
use Moose::Util::TypeConstraints ();
-our $VERSION = '0.05';
+our $VERSION = '0.06';
our $AUTHORITY = 'cpan:STEVAN';
__PACKAGE__->meta->add_attribute('type_coercion_map' => (
use Carp 'confess';
use Scalar::Util 'blessed';
-our $VERSION = '0.10';
+our $VERSION = '0.11';
our $AUTHORITY = 'cpan:STEVAN';
__PACKAGE__->meta->add_attribute('name' => (reader => 'name'));
use warnings;
use metaclass;
-use Scalar::Util qw(blessed);
+use Scalar::Util 'blessed';
+use Moose::Util::TypeConstraints ();
-use base 'Moose::Meta::TypeConstraint';
+our $VERSION = '0.01';
+our $AUTHORITY = 'cpan:STEVAN';
-use Moose::Util::TypeConstraints ();
+use base 'Moose::Meta::TypeConstraint';
sub new {
my $class = shift;
- my $self = $class->meta->new_object(@_, parent => Moose::Util::TypeConstraints::find_type_constraint('Object') );
+ my $self = $class->meta->new_object(@_,
+ parent => Moose::Util::TypeConstraints::find_type_constraint('Object')
+ );
$self->compile_type_constraint()
unless $self->_has_compiled_type_constraint;
return $self;
my $self = shift;
return (
$self->parent,
- map { Moose::Util::TypeConstraints::find_type_constraint($_) } $self->name->meta->superclasses,
+ map {
+ # NOTE:
+ # Hmm, should this be find_or_create_type_constraint?
+ # What do you think nothingmuch??
+ # - SL
+ Moose::Util::TypeConstraints::find_type_constraint($_)
+ } $self->name->meta->superclasses,
);
}
sub hand_optimized_type_constraint {
- my $self = shift;
+ my $self = shift;
my $class = $self->name;
sub { blessed( $_[0] ) && $_[0]->isa($class) }
}
1;
__END__
+
=pod
=head1 NAME
=over 4
-=item new
+=item B<new>
-=item hand_optimized_type_constraint
+=item B<hand_optimized_type_constraint>
-=item has_hand_optimized_type_constraint
+=item B<has_hand_optimized_type_constraint>
-=item is_a_type_of
+=item B<is_a_type_of>
-=item is_subtype_of
+=item B<is_subtype_of>
-=item parents
+=item B<parents>
Return all the parent types, corresponding to the parent classes.
+=item B<meta>
+
=back
+=head1 BUGS
+
+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 AUTHOR
+
+Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2006-2008 by Infinity Interactive, Inc.
+
+L<http://www.iinteractive.com>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
=cut
Moose::Meta::TypeConstraint::Parameterized - Higher Order type constraints for Moose
-=head1 DESCRIPTION
-
=head1 METHODS
=over 4
use Carp 'confess';
-our $VERSION = '0.09';
+our $VERSION = '0.10';
our $AUTHORITY = 'cpan:STEVAN';
sub new {
use Scalar::Util 'blessed', 'reftype';
use Sub::Exporter;
-our $VERSION = '0.19';
+our $VERSION = '0.20';
our $AUTHORITY = 'cpan:STEVAN';
## --------------------------------------------------------
-#!/usr/bin/perl
-
-=begin comment
-
-04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
-04:09 <@konobi> or utilxs.tar.gz iirc
-
-=cut
-
package Moose::Util::TypeConstraints::OptimizedConstraints;
use strict;
use warnings;
-use Scalar::Util qw(blessed looks_like_number);
+use Scalar::Util 'blessed', 'looks_like_number';
+
+our $VERSION = '0.01';
+our $AUTHORITY = 'cpan:STEVAN';
sub Value { defined($_[0]) && !ref($_[0]) }
{
no warnings 'uninitialized';
sub ScalarRef { ref($_[0]) eq 'SCALAR' }
- sub ArrayRef { ref($_[0]) eq 'ARRAY' }
- sub HashRef { ref($_[0]) eq 'HASH' }
- sub CodeRef { ref($_[0]) eq 'CODE' }
+ sub ArrayRef { ref($_[0]) eq 'ARRAY' }
+ sub HashRef { ref($_[0]) eq 'HASH' }
+ sub CodeRef { ref($_[0]) eq 'CODE' }
sub RegexpRef { ref($_[0]) eq 'Regexp' }
- sub GlobRef { ref($_[0]) eq 'GLOB' }
+ sub GlobRef { ref($_[0]) eq 'GLOB' }
}
sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) }
sub Role { blessed($_[0]) && $_[0]->can('does') }
+# NOTE:
+# we have XS versions too, ...
+# 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
+# 04:09 <@konobi> or utilxs.tar.gz iirc
-__PACKAGE__
+1;
__END__
Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
bodies for various moose types
-=head1 SYNOPSIS
-
=head1 DESCRIPTION
-This file contains optimized versions of Moose type constraints.
+This file contains the hand optimized versions of Moose type constraints.
=head1 FUNCTIONS
=item Role
=back
+
+=head1 BUGS
+
+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 AUTHOR
+
+Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2006-2008 by Infinity Interactive, Inc.
+
+L<http://www.iinteractive.com>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 2;
use Test::Exception;
BEGIN {
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 40;
use Test::Exception;
BEGIN {
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 20;
use Test::Exception;
BEGIN {
ok(!My::OtherRole->meta->requires_method('foo'), '... and the &foo method is not required');
ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
+{
+ package Foo::Role;
+ use Moose::Role;
+
+ sub foo { 'Foo::Role::foo' }
+
+ package Bar::Role;
+ use Moose::Role;
+
+ sub foo { 'Bar::Role::foo' }
+
+ package Baz::Role;
+ use Moose::Role;
+
+ sub foo { 'Baz::Role::foo' }
+
+ package My::Foo::Class;
+ use Moose;
+
+ ::lives_ok {
+ with 'Foo::Role' => { excludes => 'foo' },
+ 'Bar::Role' => { excludes => 'foo' },
+ 'Baz::Role';
+ } '... composed our roles correctly';
+
+ package My::Foo::Class::Broken;
+ use Moose;
+
+ ::throws_ok {
+ with 'Foo::Role',
+ 'Bar::Role' => { excludes => 'foo' },
+ 'Baz::Role';
+ } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo\' to be implemented by \'My::Foo::Class::Broken\'/,
+ '... composed our roles correctly';
+}
+
+{
+ my $foo = My::Foo::Class->new;
+ isa_ok($foo, 'My::Foo::Class');
+ can_ok($foo, 'foo');
+ is($foo->foo, 'Baz::Role::foo', '... got the right method');
+}
+
+{
+ package My::Foo::Role;
+ use Moose::Role;
+
+ ::lives_ok {
+ with 'Foo::Role' => { excludes => 'foo' },
+ 'Bar::Role' => { excludes => 'foo' },
+ 'Baz::Role';
+ } '... composed our roles correctly';
+}
+
+ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method");
+ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required');
+
+{
+ package My::Foo::Role::Other;
+ use Moose::Role;
+
+ ::lives_ok {
+ with 'Foo::Role',
+ 'Bar::Role' => { excludes => 'foo' },
+ 'Baz::Role';
+ } '... composed our roles correctly';
+}
+ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method");
+ok(My::Foo::Role::Other->meta->requires_method('foo'), '... and the &foo method is required');
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 31;
use Test::Exception;
BEGIN {
ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
+{
+ package Foo::Role;
+ use Moose::Role;
+
+ sub foo { 'Foo::Role::foo' }
+
+ package Bar::Role;
+ use Moose::Role;
+
+ sub foo { 'Bar::Role::foo' }
+ package Baz::Role;
+ use Moose::Role;
+
+ sub foo { 'Baz::Role::foo' }
+
+ package My::Foo::Class;
+ use Moose;
+
+ ::lives_ok {
+ with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
+ 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' },
+ 'Baz::Role';
+ } '... composed our roles correctly';
+
+ package My::Foo::Class::Broken;
+ use Moose;
+
+ ::throws_ok {
+ with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
+ 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
+ 'Baz::Role';
+ } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo_foo\' to be implemented by \'My::Foo::Class::Broken\'/,
+ '... composed our roles correctly';
+}
+{
+ my $foo = My::Foo::Class->new;
+ isa_ok($foo, 'My::Foo::Class');
+ can_ok($foo, $_) for qw/foo foo_foo bar_foo/;
+ is($foo->foo, 'Baz::Role::foo', '... got the right method');
+ is($foo->foo_foo, 'Foo::Role::foo', '... got the right method');
+ is($foo->bar_foo, 'Bar::Role::foo', '... got the right method');
+}
+
+{
+ package My::Foo::Role;
+ use Moose::Role;
+
+ ::lives_ok {
+ with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
+ 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' },
+ 'Baz::Role';
+ } '... composed our roles correctly';
+}
+
+ok(My::Foo::Role->meta->has_method($_), "we have a $_ method") for qw/foo foo_foo bar_foo/;;
+ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required');
+
+
+{
+ package My::Foo::Role::Other;
+ use Moose::Role;
+
+ ::lives_ok {
+ with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
+ 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
+ 'Baz::Role';
+ } '... composed our roles correctly';
+}
+ok(!My::Foo::Role::Other->meta->has_method('foo_foo'), "we dont have a foo_foo method");
+ok(My::Foo::Role::Other->meta->requires_method('foo_foo'), '... and the &foo method is required');
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 10;
+use Test::Exception;
+
+BEGIN {
+ use_ok('Moose');
+}
+
+{
+ package Foo;
+ use Moose::Role;
+
+ sub foo { 'Foo::foo' }
+ sub bar { 'Foo::bar' }
+ sub baz { 'Foo::baz' }
+ sub gorch { 'Foo::gorch' }
+
+ package Bar;
+ use Moose::Role;
+
+ sub foo { 'Bar::foo' }
+ sub bar { 'Bar::bar' }
+ sub baz { 'Bar::baz' }
+ sub gorch { 'Bar::gorch' }
+
+ package Baz;
+ use Moose::Role;
+
+ sub foo { 'Baz::foo' }
+ sub bar { 'Baz::bar' }
+ sub baz { 'Baz::baz' }
+ sub gorch { 'Baz::gorch' }
+
+ package Gorch;
+ use Moose::Role;
+
+ sub foo { 'Gorch::foo' }
+ sub bar { 'Gorch::bar' }
+ sub baz { 'Gorch::baz' }
+ sub gorch { 'Gorch::gorch' }
+}
+
+{
+ package My::Class;
+ use Moose;
+
+ ::lives_ok {
+ with 'Foo' => { excludes => [qw/bar baz gorch/], alias => { gorch => 'foo_gorch' } },
+ 'Bar' => { excludes => [qw/foo baz gorch/] },
+ 'Baz' => { excludes => [qw/foo bar gorch/], alias => { foo => 'baz_foo', bar => 'baz_bar' } },
+ 'Gorch' => { excludes => [qw/foo bar baz/] };
+ } '... everything works out all right';
+}
+
+my $c = My::Class->new;
+isa_ok($c, 'My::Class');
+
+is($c->foo, 'Foo::foo', '... got the right method');
+is($c->bar, 'Bar::bar', '... got the right method');
+is($c->baz, 'Baz::baz', '... got the right method');
+is($c->gorch, 'Gorch::gorch', '... got the right method');
+
+is($c->foo_gorch, 'Foo::gorch', '... got the right method');
+is($c->baz_foo, 'Baz::foo', '... got the right method');
+is($c->baz_bar, 'Baz::bar', '... got the right method');
+
+
+
+
+
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 17;
use Test::Exception;
BEGIN {
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 15;
use Test::Exception;
BEGIN {
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 19;
use Test::Exception;
BEGIN {
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 10;
use Test::Exception;
BEGIN {
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 22;
use Test::Exception;
BEGIN {
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 11;
use Test::Exception;
BEGIN {
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 9;
use Test::Exception;
BEGIN {
use strict;
use warnings;
-use Test::More 'no_plan';
+use Test::More tests => 7;
BEGIN {
use_ok('Moose::Util::TypeConstraints');
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 28;
=pod