package MooseX::AttributeHelpers;
- our $VERSION = '0.08';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
+ use Moose 0.56 ();
+
use MooseX::AttributeHelpers::Meta::Method::Provided;
+ use MooseX::AttributeHelpers::Meta::Method::Curried;
+use MooseX::AttributeHelpers::Trait::Counter;
+use MooseX::AttributeHelpers::Trait::Number;
+use MooseX::AttributeHelpers::Trait::String;
+use MooseX::AttributeHelpers::Trait::Collection::List;
+use MooseX::AttributeHelpers::Trait::Collection::Array;
+use MooseX::AttributeHelpers::Trait::Collection::Hash;
+use MooseX::AttributeHelpers::Trait::Collection::ImmutableHash;
+use MooseX::AttributeHelpers::Trait::Collection::Bag;
+
use MooseX::AttributeHelpers::Counter;
use MooseX::AttributeHelpers::Number;
use MooseX::AttributeHelpers::String;
package MooseX::AttributeHelpers::Collection::Array;
use Moose;
- our $VERSION = '0.01';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-use MooseX::AttributeHelpers::MethodProvider::Array;
-
-extends 'MooseX::AttributeHelpers::Collection';
-
-has '+method_provider' => (
- default => 'MooseX::AttributeHelpers::MethodProvider::Array'
-);
-
-sub helper_type { 'ArrayRef' }
+extends 'Moose::Meta::Attribute';
+with 'MooseX::AttributeHelpers::Trait::Collection::Array';
no Moose;
package MooseX::AttributeHelpers::Collection::Bag;
use Moose;
-use Moose::Util::TypeConstraints;
- our $VERSION = '0.01';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-use MooseX::AttributeHelpers::MethodProvider::Bag;
-
-extends 'MooseX::AttributeHelpers::Collection';
-
-has '+method_provider' => (
- default => 'MooseX::AttributeHelpers::MethodProvider::Bag'
-);
-
-subtype 'Bag' => as 'HashRef[Int]';
-
-sub helper_type { 'Bag' }
-
-before 'process_options_for_provides' => sub {
- my ($self, $options, $name) = @_;
-
- # Set some default attribute options here unless already defined
- if ((my $type = $self->helper_type) && !exists $options->{isa}){
- $options->{isa} = $type;
- }
-
- $options->{default} = sub { +{} } unless exists $options->{default};
-};
+extends 'Moose::Meta::Attribute';
+with 'MooseX::AttributeHelpers::Trait::Collection::Bag';
no Moose;
-no Moose::Util::TypeConstraints;
# register the alias ...
package # hide me from search.cpan.org
package MooseX::AttributeHelpers::Collection::Hash;
use Moose;
- our $VERSION = '0.02';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-use MooseX::AttributeHelpers::MethodProvider::Hash;
-
-extends 'MooseX::AttributeHelpers::Collection';
-
-has '+method_provider' => (
- default => 'MooseX::AttributeHelpers::MethodProvider::Hash'
-);
-
-sub helper_type { 'HashRef' }
+extends 'Moose::Meta::Attribute';
+with 'MooseX::AttributeHelpers::Trait::Collection::Hash';
no Moose;
package MooseX::AttributeHelpers::Collection::ImmutableHash;
use Moose;
- our $VERSION = '0.01';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-use MooseX::AttributeHelpers::MethodProvider::ImmutableHash;
-
-extends 'MooseX::AttributeHelpers::Collection';
-
-has '+method_provider' => (
- default => 'MooseX::AttributeHelpers::MethodProvider::ImmutableHash'
-);
-
-sub helper_type { 'HashRef' }
+extends 'Moose::Meta::Attribute';
+with 'MooseX::AttributeHelpers::Trait::Collection::ImmutableHash';
no Moose;
package MooseX::AttributeHelpers::Collection::List;
use Moose;
- our $VERSION = '0.01';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-use MooseX::AttributeHelpers::MethodProvider::List;
-
-extends 'MooseX::AttributeHelpers::Collection';
-
-has '+method_provider' => (
- default => 'MooseX::AttributeHelpers::MethodProvider::List'
-);
-
-sub helper_type { 'ArrayRef' }
+extends 'Moose::Meta::Attribute';
+with 'MooseX::AttributeHelpers::Trait::Collection::List';
no Moose;
package MooseX::AttributeHelpers::Counter;
use Moose;
- our $VERSION = '0.03';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-use MooseX::AttributeHelpers::MethodProvider::Counter;
-
-extends 'MooseX::AttributeHelpers::Base';
-
-has '+method_provider' => (
- default => 'MooseX::AttributeHelpers::MethodProvider::Counter'
-);
-
-sub helper_type { 'Num' }
-
-before 'process_options_for_provides' => sub {
- my ($self, $options, $name) = @_;
-
- # Set some default attribute options here unless already defined
- if ((my $type = $self->helper_type) && !exists $options->{isa}){
- $options->{isa} = $type;
- }
-
- $options->{is} = 'ro' unless exists $options->{is};
- $options->{default} = 0 unless exists $options->{default};
-};
-
-after 'check_provides_values' => sub {
- my $self = shift;
- my $provides = $self->provides;
-
- unless (scalar keys %$provides) {
- my $method_constructors = $self->method_constructors;
- my $attr_name = $self->name;
-
- foreach my $method (keys %$method_constructors) {
- $provides->{$method} = ($method . '_' . $attr_name);
- }
- }
-};
+extends 'Moose::Meta::Attribute';
+with 'MooseX::AttributeHelpers::Trait::Counter';
no Moose;
package MooseX::AttributeHelpers::Number;
use Moose;
- our $VERSION = '0.02';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-extends 'MooseX::AttributeHelpers::Base';
+extends 'Moose::Meta::Attribute';
+with 'MooseX::AttributeHelpers::Trait::Number';
-sub helper_type { 'Num' }
-
-# NOTE:
-# we don't use the method provider for this
-# module since many of the names of the provied
-# methods would conflict with keywords
-# - SL
-
-has '+method_constructors' => (
- default => sub {
- return +{
- set => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $_[1]) };
- },
- add => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) + $_[1]) };
- },
- sub => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) - $_[1]) };
- },
- mul => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) * $_[1]) };
- },
- div => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) / $_[1]) };
- },
- mod => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) % $_[1]) };
- },
- abs => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], abs($reader->($_[0])) ) };
- },
- }
- }
-);
-
no Moose;
# register the alias ...
package MooseX::AttributeHelpers::String;
use Moose;
- our $VERSION = '0.01';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-use MooseX::AttributeHelpers::MethodProvider::String;
-
-extends 'MooseX::AttributeHelpers::Base';
-
-has '+method_provider' => (
- default => 'MooseX::AttributeHelpers::MethodProvider::String'
-);
-
-sub helper_type { 'Str' }
-
-before 'process_options_for_provides' => sub {
- my ($self, $options, $name) = @_;
-
- # Set some default attribute options here unless already defined
- if ((my $type = $self->helper_type) && !exists $options->{isa}){
- $options->{isa} = $type;
- }
-
- $options->{is} = 'rw' unless exists $options->{is};
- $options->{default} = '' unless exists $options->{default};
-};
-
-after 'check_provides_values' => sub {
- my $self = shift;
- my $provides = $self->provides;
-
- unless (scalar keys %$provides) {
- my $method_constructors = $self->method_constructors;
- my $attr_name = $self->name;
-
- foreach my $method (keys %$method_constructors) {
- $provides->{$method} = ($method . '_' . $attr_name);
- }
- }
-};
+extends 'Moose::Meta::Attribute';
+with 'MooseX::AttributeHelpers::Trait::String';
no Moose;
-package MooseX::AttributeHelpers::Base;
-use Moose;
+package MooseX::AttributeHelpers::Trait::Base;
+use Moose::Role;
use Moose::Util::TypeConstraints;
- our $VERSION = '0.04';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-extends 'Moose::Meta::Attribute';
+requires 'helper_type';
# this is the method map you define ...
has 'provides' => (
if blessed($method) &&
$method->isa('MooseX::AttributeHelpers::Meta::Method::Provided');
}
+
+ # curries accessors
+ foreach my $key (keys %{$attr->curries}) {
+ my $method_name = $attr->curries->{$key};
+ my $method = $class->get_method($method_name);
+ $class->remove_method($method_name)
+ if blessed($method) &&
+ $method->isa('MooseX::AttributeHelpers::Meta::Method::Provided');
+ }
};
-no Moose;
+no Moose::Role;
no Moose::Util::TypeConstraints;
1;
-package MooseX::AttributeHelpers::Collection;
-use Moose;
+package MooseX::AttributeHelpers::Trait::Collection;
+use Moose::Role;
- our $VERSION = '0.03';
+ our $VERSION = '0.17';
+ $VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
-extends 'MooseX::AttributeHelpers::Base';
+with 'MooseX::AttributeHelpers::Trait::Base';
-no Moose;
+no Moose::Role;
1;