Remove loading from Attribute::Native, leave only register_implementations there
Give Native traits their shortnames by default (with just 'use Moose')
use Moose::Util::TypeConstraints;
use Moose::Util ();
+use Moose::Attribute::Native;
+
sub throw_error {
# FIXME This
shift;
-package Moose::AttributeHelpers;
+package Moose::Attribute::Native;
our $VERSION = '0.87';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-use Moose ();
-
-use Moose::Meta::Attribute::Trait::Native::Bool;
-use Moose::Meta::Attribute::Trait::Native::Counter;
-use Moose::Meta::Attribute::Trait::Native::Number;
-use Moose::Meta::Attribute::Trait::Native::String;
-use Moose::Meta::Attribute::Trait::Native::Array;
-use Moose::Meta::Attribute::Trait::Native::Hash;
+my @trait_names = qw(Bool Counter Number String Array Hash);
+
+for my $trait_name (@trait_names) {
+ my $trait_class = "Moose::Meta::Attribute::Trait::Native::$trait_name";
+ my $meta = Class::MOP::Class->initialize(
+ "Moose::Meta::Attribute::Custom::Trait::$trait_name"
+ );
+ if ($meta->find_method_by_name('register_implementation')) {
+ my $class = $meta->name->register_implementation;
+ Moose->throw_error(
+ "An implementation for $trait_name already exists " .
+ "(found '$class' when trying to register '$trait_class')"
+ );
+ }
+ $meta->add_method(register_implementation => sub {
+ # resolve_metatrait_alias will load classes anyway, but throws away
+ # their error message; we WANT to die if there's a problem
+ Class::MOP::load_class($trait_class);
+ return $trait_class;
+ });
+}
1;
=head1 NAME
-Moose::AttributeHelpers - Extend your attribute interfaces
+Moose::Attribute::Native - Extend your attribute interfaces
=head1 SYNOPSIS
package MyClass;
use Moose;
- use Moose::AttributeHelpers;
+ use Moose::Attribute::Native;
has 'mapping' => (
traits => [ 'Hash' ],
use Moose::Meta::Attribute::Trait::Native::MethodProvider::Array;
-with 'Moose::Meta::Attribute::Trait::Native::Collection';
+with 'Moose::Meta::Attribute::Trait::Native';
has 'method_provider' => (
is => 'ro',
no Moose::Role;
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Trait::Array;
-sub register_implementation {
- 'Moose::Meta::Attribute::Trait::Native::Array'
-}
-
-
1;
__END__
no Moose::Role;
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Trait::Bool;
-sub register_implementation { 'Moose::Meta::Attribute::Trait::Native::Bool' }
-
1;
=pod
+++ /dev/null
-
-package Moose::Meta::Attribute::Trait::Native::Collection;
-use Moose::Role;
-
-our $VERSION = '0.87';
-$VERSION = eval $VERSION;
-our $AUTHORITY = 'cpan:STEVAN';
-
-with 'Moose::Meta::Attribute::Trait::Native';
-
-no Moose::Role;
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::Meta::Attribute::Trait::Native::Collection - Base role for all collection type helpers
-
-=head1 DESCRIPTION
-
-Documentation to come.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=item B<container_type>
-
-=item B<container_type_constraint>
-
-=item B<has_container_type>
-
-=item B<process_options_for_handles>
-
-=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
-
-Stevan Little E<lt>stevan@iinteractive.comE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2007-2009 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
no Moose::Role;
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Trait::Counter;
-sub register_implementation { 'Moose::Meta::Attribute::Trait::Native::Counter' }
-
1;
__END__
use Moose::Meta::Attribute::Trait::Native::MethodProvider::Hash;
-with 'Moose::Meta::Attribute::Trait::Native::Collection';
+with 'Moose::Meta::Attribute::Trait::Native';
has 'method_provider' => (
is => 'ro',
no Moose::Role;
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Trait::Hash;
-sub register_implementation {
- 'Moose::Meta::Attribute::Trait::Native::Hash'
-}
-
-
1;
__END__
no Moose::Role;
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Trait::Number;
-sub register_implementation { 'Moose::Meta::Attribute::Trait::Native::Number' }
-
1;
=pod
no Moose::Role;
-package # hide me from search.cpan.org
- Moose::Meta::Attribute::Custom::Trait::String;
-sub register_implementation { 'Moose::Meta::Attribute::Trait::Native::String' }
-
1;
__END__
use Test::More tests => 1;
+use Moose ();
BEGIN {
- use_ok('Moose::AttributeHelpers');
-}
\ No newline at end of file
+ use_ok('Moose::Attribute::Native');
+}
package Stuffed::Role;
use Moose::Role;
- use Moose::AttributeHelpers;
has 'options' => (
traits => ['Array'],
package Bulkie::Role;
use Moose::Role;
- use Moose::AttributeHelpers;
has 'stuff' => (
traits => ['Array'],
{
package MyHomePage;
use Moose;
- use Moose::AttributeHelpers;
has 'counter' => ( traits => ['Counter'] );
}
{
package MyHomePage;
use Moose;
- use Moose::AttributeHelpers;
has 'counter' => (
traits => ['Counter'],
package Subject;
use Moose::Role;
- use Moose::AttributeHelpers;
has observers => (
traits => ['Array'],
package Counter;
use Moose;
- use Moose::AttributeHelpers;
with 'Subject';
{
package MyHomePage;
use Moose;
- use Moose::AttributeHelpers;
has 'counter' => (
traits => ['Counter'],
package Stuff;
use Moose;
- use Moose::AttributeHelpers;
has 'options' => (
traits => ['Array'],
{
package Stuff;
use Moose;
- use Moose::AttributeHelpers;
has 'options' => (
traits => ['Hash'],
{
package Real;
use Moose;
- use Moose::AttributeHelpers;
has 'integer' => (
traits => ['Number'],
{
package Stuff;
use Moose;
- use Moose::AttributeHelpers;
has '_options' => (
traits => ['Array'],
{
package MyHomePage;
use Moose;
- use Moose::AttributeHelpers;
has 'string' => (
traits => ['String'],
{
package Room;
use Moose;
- use Moose::AttributeHelpers;
has 'is_lit' => (
traits => ['Bool'],