From: Paul Driver Date: Thu, 10 Apr 2008 21:22:49 +0000 (+0000) Subject: Composite now implemented. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=786dbc3d10c2609d567097725efcbbc833e82f4b;p=gitmo%2FMooseX-AttributeHelpers.git Composite now implemented. --- diff --git a/lib/MooseX/AttributeHelpers.pm b/lib/MooseX/AttributeHelpers.pm index 041edb6..8434aeb 100644 --- a/lib/MooseX/AttributeHelpers.pm +++ b/lib/MooseX/AttributeHelpers.pm @@ -1,9 +1,10 @@ - package MooseX::AttributeHelpers; our $VERSION = '0.08'; our $AUTHORITY = 'cpan:STEVAN'; +use MooseX::AttributeHelpers::Composite; + use MooseX::AttributeHelpers::Meta::Method::Provided; use MooseX::AttributeHelpers::Counter; @@ -102,6 +103,12 @@ Hashes with no change methods. =back +=head1 COMPOSITE + +The methods provided by the above methods can be selectively composed with the +metaclass L, which is also +available in L form. + =head1 CAVEAT This is an early release of this module. Right now it is in great need diff --git a/lib/MooseX/AttributeHelpers/Base.pm b/lib/MooseX/AttributeHelpers/Base.pm index 9938528..1dd1f44 100644 --- a/lib/MooseX/AttributeHelpers/Base.pm +++ b/lib/MooseX/AttributeHelpers/Base.pm @@ -1,7 +1,7 @@ - package MooseX::AttributeHelpers::Base; use Moose; use Moose::Util::TypeConstraints; +use MooseX::AttributeHelpers::MethodProvider; use MooseX::AttributeHelpers::Meta::Method::Provided; our $VERSION = '0.04'; @@ -16,37 +16,6 @@ has 'provides' => ( default => sub {{}} ); -# these next two are the possible methods -# you can use in the 'provides' map. - -# provide a Class or Role which we can -# collect the method providers from -has 'method_provider' => ( - is => 'ro', - isa => 'ClassName', - predicate => 'has_method_provider', -); - -# or you can provide a HASH ref of anon subs -# yourself. This will also collect and store -# the methods from a method_provider as well -has 'method_constructors' => ( - is => 'ro', - isa => 'HashRef', - lazy => 1, - default => sub { - my $self = shift; - return +{} unless $self->has_method_provider; - # or grab them from the role/class - my $method_provider = $self->method_provider->meta; - return +{ - map { - $_ => $method_provider->get_method($_) - } $method_provider->get_method_list - }; - }, -); - # extend the parents stuff to make sure # certain bits are now required ... has '+$!default' => (required => 1); @@ -54,11 +23,16 @@ has '+type_constraint' => (required => 1); ## Methods called prior to instantiation -# (overridden by Sugar or plain subclasses) -sub helper_type {()} +# For overriding sub default_options {} sub auto_provide {0} +# Do not override both of these things. You will be eaten. +sub method_provider {} +sub method_constructors { + get_provider_methods($_[0]->method_provider, ':all') +} + sub process_options_for_provides { my ($self, $options) = @_; @@ -69,18 +43,20 @@ sub process_options_for_provides { } } - if (my $type = $self->helper_type) { - $options->{isa} = $type unless exists $options->{isa}; - - my $isa = $options->{isa}; - - unless (blessed($isa) && $isa->isa('Moose::Meta::TypeConstraint')) { - $isa = Moose::Util::TypeConstraints::find_or_create_type_constraint($isa); - } - - ($isa->is_a_type_of($type)) - || confess "The type constraint for a $type ($options->{isa}) must be a subtype of $type"; + return unless $self->method_provider; + my $type = get_provider_type($self->method_provider); + $options->{isa} = $type unless exists $options->{isa}; + my $isa = $options->{isa}; + + unless (blessed($isa) && $isa->isa('Moose::Meta::TypeConstraint')) { + $isa = Moose::Util::TypeConstraints::find_or_create_type_constraint( + $isa + ); } + + confess "The type constraint for a $type ($options->{isa}) " + . "must be a subtype of $type" + unless $isa->is_a_type_of($type); } before '_process_options' => sub { @@ -162,6 +138,33 @@ after 'remove_accessors' => sub { } }; +sub sugar { + my ($class, %info) = @_; + my $meta = $class->meta; + + $meta->add_method('default_options', sub {$info{default_options}}); + $meta->add_method('auto_provide', sub {$info{auto_provide} || 0}); + + my $provider = $info{method_provider}; + my $constructors = $info{method_constructors}; + + confess "Supply either method_provider or method_constructors" + if ($provider && $constructors) || !($provider || $constructors); + + if(my $provider = $info{method_provider}) { + $meta->add_method('method_provider' => sub { $provider }); + } + elsif (my $cons = $info{method_constructors}) { + $meta->add_method('method_constructors' => sub { $cons }); + } + + if (my $s = $info{shortcut}) { + $meta->create("Moose::Meta::Attribute::Custom::$s", + methods => {register_implementation => sub { $class }}, + ); + } +} + no Moose; no Moose::Util::TypeConstraints; @@ -175,12 +178,34 @@ __END__ MooseX::AttributeHelpers::Base - Base class for attribute helpers +SYNOPSIS + + package MooseX::AttributeHelpers::Counter; + use Moose; + use MooseX::AttributeHelpers::MethodProvider::Counter; + + extends 'MooseX::AttributeHelpers::Base'; + + __PACKAGE__->sugar( + default_options => { + is => 'ro', + default => 0, + }, + + auto_provide => 1, + method_provider => 'Counter', + shortcut => 'Counter', + ); + + no Moose; + + 1; + =head1 DESCRIPTION This class is what you inherit from when you want to make a new -AttributeHelper. Unless you are doing something quite fancy, your needs -should be met by L, which has a nice, terse -syntax and some convenience, but you should still subclass this class. +AttributeHelper metaclass. Most of the work is done for you by the class +method I if you're doing something basic. =head1 ATTRIBUTES @@ -191,18 +216,6 @@ syntax and some convenience, but you should still subclass this class. This is the map of metaclass methods to methods that will be installed in your class, e.g. add => 'add_to_number'. -=item B - -The name of a class or role to be used as source material for the above map. -In the above example, the method provider's "add" method would be used to -construct a method to install into the attribute holder's class. - -=item B - -You can optionally supply a hashref of names to subs instead of a class to be -used as method constructors, but by default this is pulled from -method_provider. - =back =head1 EXTENDED ATTRIBUTES @@ -223,7 +236,18 @@ C is now required. =over 4 -=item B +=item B + +The name of a method provider. Usually one Ls a package +that defines a method provider in the registry first, but you can just as well +define one in your own code. See L +for details. + +=item B + +You can optionally supply a hashref of names to subs instead of a class to be +used as method constructors. In that case, your methods won't be available +for use by L. =item B @@ -237,21 +261,24 @@ Returns a Maybe[Hashref] of attribution specifications to fill in if they are not overridden by the implementing attribute. This is intended to be overridden in subclasses. -=item B +=item B -This forces all attributes using this metaclass to be a subtype of -helper_type. This is intended to be overridden in subclasses. +A convenience method for subclassing declaratively. See L<"SYNOPSIS"> for an +example. The shortcut option creates a package under +Moose::Meta::Attribute::Custom to make it easier for users to find your +metaclass, but you can do this manually if you desire. =item B -=item B - =item B =item B =item B +These are hooks you can use to change the behavior of the metaclass; read the +source for inspiration. + =back =head1 BUGS diff --git a/lib/MooseX/AttributeHelpers/Collection/Array.pm b/lib/MooseX/AttributeHelpers/Collection/Array.pm index 47e7b90..8a83eaa 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Array.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Array.pm @@ -1,21 +1,18 @@ - package MooseX::AttributeHelpers::Collection::Array; use Moose; -use MooseX::AttributeHelpers::Sugar; +use MooseX::AttributeHelpers::MethodProvider::Collection::Array; extends 'MooseX::AttributeHelpers::Collection'; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -define_attribute_helper ( - helper_type => 'ArrayRef', - method_provider => 'MooseX::AttributeHelpers::MethodProvider::Array', +__PACKAGE__->sugar( + method_provider => 'Collection::Array', shortcut => 'Collection::Array', ); no Moose; -no MooseX::AttributeHelpers::Sugar; 1; diff --git a/lib/MooseX/AttributeHelpers/Collection/Bag.pm b/lib/MooseX/AttributeHelpers/Collection/Bag.pm index 09beebe..96d0ba8 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Bag.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Bag.pm @@ -1,26 +1,19 @@ - package MooseX::AttributeHelpers::Collection::Bag; use Moose; -use Moose::Util::TypeConstraints; -use MooseX::AttributeHelpers::Sugar; +use MooseX::AttributeHelpers::MethodProvider::Collection::Bag; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; extends 'MooseX::AttributeHelpers::Collection'; -subtype 'Bag' => as 'HashRef[Int]'; - -define_attribute_helper ( +__PACKAGE__->sugar( default_options => { default => sub { {} } }, - helper_type => 'Bag', - method_provider => 'MooseX::AttributeHelpers::MethodProvider::Bag', + method_provider => 'Collection::Bag', shortcut => 'Collection::Bag', ); no Moose; -no Moose::Util::TypeConstraints; -no MooseX::AttributeHelpers::Sugar; 1; diff --git a/lib/MooseX/AttributeHelpers/Collection/Hash.pm b/lib/MooseX/AttributeHelpers/Collection/Hash.pm index c2d6acb..5babe6b 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Hash.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Hash.pm @@ -1,21 +1,18 @@ - package MooseX::AttributeHelpers::Collection::Hash; use Moose; -use MooseX::AttributeHelpers::Sugar; +use MooseX::AttributeHelpers::MethodProvider::Collection::Hash; extends 'MooseX::AttributeHelpers::Collection'; our $VERSION = '0.02'; our $AUTHORITY = 'cpan:STEVAN'; -define_attribute_helper ( - helper_type => 'HashRef', - method_provider => 'MooseX::AttributeHelpers::MethodProvider::Hash', +__PACKAGE__->sugar( + method_provider => 'Collection::Hash', shortcut => 'Collection::Hash', ); no Moose; -no MooseX::AttributeHelpers::Sugar; 1; diff --git a/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm b/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm index fc9b06e..0c75d55 100644 --- a/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm +++ b/lib/MooseX/AttributeHelpers/Collection/ImmutableHash.pm @@ -1,22 +1,18 @@ - package MooseX::AttributeHelpers::Collection::ImmutableHash; use Moose; -use MooseX::AttributeHelpers::Sugar; +use MooseX::AttributeHelpers::MethodProvider::Collection::ImmutableHash; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; extends 'MooseX::AttributeHelpers::Collection'; -define_attribute_helper ( - helper_type => 'HashRef', - method_provider => - 'MooseX::AttributeHelpers::MethodProvider::ImmutableHash', +__PACKAGE__->sugar( + method_provider => 'Collection::ImmutableHash', shortcut => 'Collection::ImmutableHash', ); no Moose; -no MooseX::AttributeHelpers::Sugar; 1; diff --git a/lib/MooseX/AttributeHelpers/Collection/List.pm b/lib/MooseX/AttributeHelpers/Collection/List.pm index 272f95f..687a3ed 100644 --- a/lib/MooseX/AttributeHelpers/Collection/List.pm +++ b/lib/MooseX/AttributeHelpers/Collection/List.pm @@ -1,21 +1,18 @@ - package MooseX::AttributeHelpers::Collection::List; use Moose; -use MooseX::AttributeHelpers::Sugar; +use MooseX::AttributeHelpers::MethodProvider::Collection::List; extends 'MooseX::AttributeHelpers::Collection'; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -define_attribute_helper ( - helper_type => 'ArrayRef', - method_provider => 'MooseX::AttributeHelpers::MethodProvider::List', +__PACKAGE__->sugar( + method_provider => 'Collection::List', shortcut => 'Collection::List', ); no Moose; -no MooseX::AttributeHelpers::Sugar; 1; diff --git a/lib/MooseX/AttributeHelpers/Counter.pm b/lib/MooseX/AttributeHelpers/Counter.pm index 4626f7f..eaabe06 100644 --- a/lib/MooseX/AttributeHelpers/Counter.pm +++ b/lib/MooseX/AttributeHelpers/Counter.pm @@ -1,27 +1,24 @@ - package MooseX::AttributeHelpers::Counter; use Moose; -use MooseX::AttributeHelpers::Sugar; +use MooseX::AttributeHelpers::MethodProvider::Counter; extends 'MooseX::AttributeHelpers::Base'; our $VERSION = '0.03'; our $AUTHORITY = 'cpan:STEVAN'; -define_attribute_helper ( +__PACKAGE__->sugar( default_options => { is => 'ro', default => 0, }, - helper_type => 'Num', - method_provider => 'MooseX::AttributeHelpers::MethodProvider::Counter', auto_provide => 1, + method_provider => 'Counter', shortcut => 'Counter', ); no Moose; -no MooseX::AttributeHelpers::Sugar; 1; diff --git a/lib/MooseX/AttributeHelpers/MethodProvider/Counter.pm b/lib/MooseX/AttributeHelpers/MethodProvider/Counter.pm index 2dce27c..a90edb9 100644 --- a/lib/MooseX/AttributeHelpers/MethodProvider/Counter.pm +++ b/lib/MooseX/AttributeHelpers/MethodProvider/Counter.pm @@ -1,24 +1,28 @@ - package MooseX::AttributeHelpers::MethodProvider::Counter; -use Moose::Role; +use MooseX::AttributeHelpers::MethodProvider; our $VERSION = '0.02'; our $AUTHORITY = 'cpan:STEVAN'; -sub reset : method { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $attr->default($_[0])) }; -} - -sub inc { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) + 1) }; -} - -sub dec { - my ($attr, $reader, $writer) = @_; - return sub { $writer->($_[0], $reader->($_[0]) - 1) }; -} +add_method_provider 'Counter' => ( + type => 'Int', + provides => { + reset => sub { + my ($attr, $reader, $writer) = @_; + return sub { $writer->($_[0], $attr->default($_[0])) }; + }, + + inc => sub { + my ($attr, $reader, $writer) = @_; + return sub { $writer->($_[0], $reader->($_[0]) + 1) }; + }, + + dec => sub { + my ($attr, $reader, $writer) = @_; + return sub { $writer->($_[0], $reader->($_[0]) - 1) }; + }, + }, +); 1; @@ -29,10 +33,10 @@ __END__ =head1 NAME MooseX::AttributeHelpers::MethodProvider::Counter - + =head1 DESCRIPTION -This is a role which provides the method generators for +This is a role which provides the method generators for L. =head1 PROVIDED METHODS @@ -55,7 +59,7 @@ Resets the value stored in this slot to its default value. =head1 BUGS -All complex software has bugs lurking in it, and this module is no +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. diff --git a/lib/MooseX/AttributeHelpers/MethodProvider/Number.pm b/lib/MooseX/AttributeHelpers/MethodProvider/Number.pm index a7929d0..2a959ee 100644 --- a/lib/MooseX/AttributeHelpers/MethodProvider/Number.pm +++ b/lib/MooseX/AttributeHelpers/MethodProvider/Number.pm @@ -1,36 +1,29 @@ - package MooseX::AttributeHelpers::MethodProvider::Number; -use Moose::Role; +use MooseX::AttributeHelpers::MethodProvider; our $VERSION = '0.02'; our $AUTHORITY = 'cpan:STEVAN'; -my %ops = ( - add => '+', - sub => '-', - mul => '*', - div => '/', - mod => '%', -); - -foreach my $method (keys %ops) -{ - my $s = $ops{$method}; - __PACKAGE__->meta->alias_method($method, sub { - my ($attr, $reader, $writer) = @_; - return eval "sub { \$writer->(\$_[0], \$reader->(\$_[0]) $s \$_[1]) }"; - }); -} +my %o = (add => '+', sub => '-', mul => '*', div => '/', mod => '%'); +my %methods = map {my $m = $_; $m => sub { + my ($attr, $reader, $writer) = @_; + return eval "sub { \$writer->(\$_[0], \$reader->(\$_[0]) $o{$m} \$_[1]) }"; +}} (keys %o); -sub abs : method { +$methods{abs} = sub { my ($attr, $reader, $writer) = @_; return sub { $writer->($_[0], CORE::abs($reader->($_[0]))) }; -} +}; -sub set : method { +$methods{set} = sub { my ($attr, $reader, $writer) = @_; return sub { $writer->($_[0], $_[1]) }; -} +}; + +add_method_provider Number => ( + type => 'Num', + provides => \%methods, +); 1; @@ -41,15 +34,15 @@ __END__ =head1 NAME MooseX::AttributeHelpers::MethodProvider::Number - + =head1 DESCRIPTION -This is a role which provides the method generators for +This is a role which provides the method generators for L. =head1 PROVIDED METHODS -All methods but 'set' are plain mathematical operators, as in +All methods but 'set' are plain mathematical operators, as in C<$current_value = $current_value OP $argument> where OP is the operator listed next to the method name. @@ -76,7 +69,7 @@ provided for convenience. =head1 BUGS -All complex software has bugs lurking in it, and this module is no +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. diff --git a/lib/MooseX/AttributeHelpers/MethodProvider/String.pm b/lib/MooseX/AttributeHelpers/MethodProvider/String.pm index 98d981f..202c646 100644 --- a/lib/MooseX/AttributeHelpers/MethodProvider/String.pm +++ b/lib/MooseX/AttributeHelpers/MethodProvider/String.pm @@ -1,75 +1,76 @@ - package MooseX::AttributeHelpers::MethodProvider::String; -use Moose::Role; +use MooseX::AttributeHelpers::MethodProvider; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -sub append : method { - my ($attr, $reader, $writer) = @_; - - return sub { $writer->( $_[0], $reader->($_[0]) . $_[1] ) }; -} - -sub prepend : method { - my ($attr, $reader, $writer) = @_; - - return sub { $writer->( $_[0], $_[1] . $reader->($_[0]) ) }; -} - -sub replace : method { - my ($attr, $reader, $writer) = @_; - - return sub { - my ( $self, $regex, $replacement ) = @_; - my $v = $reader->($_[0]); - - if ( (ref($replacement)||'') eq 'CODE' ) { - $v =~ s/$regex/$replacement->()/e; - } else { - $v =~ s/$regex/$replacement/; - } - - $writer->( $_[0], $v); - }; -} - -sub match : method { - my ($attr, $reader, $writer) = @_; - return sub { $reader->($_[0]) =~ $_[1] }; -} - -sub chop : method { - my ($attr, $reader, $writer) = @_; - return sub { - my $v = $reader->($_[0]); - CORE::chop($v); - $writer->( $_[0], $v); - }; -} - -sub chomp : method { - my ($attr, $reader, $writer) = @_; - return sub { - my $v = $reader->($_[0]); - chomp($v); - $writer->( $_[0], $v); - }; -} - -sub inc : method { - my ($attr, $reader, $writer) = @_; - return sub { - my $v = $reader->($_[0]); - $v++; - $writer->( $_[0], $v); - }; -} - -sub clear : method { - my ($attr, $reader, $writer ) = @_; - return sub { $writer->( $_[0], '' ) } -} +add_method_provider String => ( + type => 'Str', + provides => { + append => sub { + my ($attr, $reader, $writer) = @_; + return sub { $writer->( $_[0], $reader->($_[0]) . $_[1] ) }; + }, + + prepend => sub { + my ($attr, $reader, $writer) = @_; + return sub { $writer->( $_[0], $_[1] . $reader->($_[0]) ) }; + }, + + replace => sub { + my ($attr, $reader, $writer) = @_; + return sub { + my ( $self, $regex, $replacement ) = @_; + my $v = $reader->($_[0]); + + if ( (ref($replacement)||'') eq 'CODE' ) { + $v =~ s/$regex/$replacement->()/e; + } else { + $v =~ s/$regex/$replacement/; + } + + $writer->( $_[0], $v); + }; + }, + + match => sub { + my ($attr, $reader, $writer) = @_; + return sub { $reader->($_[0]) =~ $_[1] }; + }, + + chop => sub { + my ($attr, $reader, $writer) = @_; + return sub { + my $v = $reader->($_[0]); + CORE::chop($v); + $writer->( $_[0], $v); + }; + }, + + chomp => sub { + my ($attr, $reader, $writer) = @_; + return sub { + my $v = $reader->($_[0]); + chomp($v); + $writer->( $_[0], $v); + }; + }, + + inc => sub { + my ($attr, $reader, $writer) = @_; + return sub { + my $v = $reader->($_[0]); + $v++; + $writer->( $_[0], $v); + }; + }, + + clear => sub { + my ($attr, $reader, $writer ) = @_; + return sub { $writer->( $_[0], '' ) } + }, + }, +); 1; @@ -80,10 +81,10 @@ __END__ =head1 NAME MooseX::AttributeHelpers::MethodProvider::String - + =head1 DESCRIPTION -This is a role which provides the method generators for +This is a role which provides the method generators for L. =head1 PROVIDED METHODS @@ -133,7 +134,7 @@ Sets the string to the empty string (not the value passed to C). =head1 BUGS -All complex software has bugs lurking in it, and this module is no +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. diff --git a/lib/MooseX/AttributeHelpers/Number.pm b/lib/MooseX/AttributeHelpers/Number.pm index 19861c3..025c210 100644 --- a/lib/MooseX/AttributeHelpers/Number.pm +++ b/lib/MooseX/AttributeHelpers/Number.pm @@ -1,20 +1,18 @@ package MooseX::AttributeHelpers::Number; use Moose; -use MooseX::AttributeHelpers::Sugar; +use MooseX::AttributeHelpers::MethodProvider::Number; extends 'MooseX::AttributeHelpers::Base'; our $VERSION = '0.02'; our $AUTHORITY = 'cpan:STEVAN'; -define_attribute_helper ( - helper_type => 'Num', - method_provider => 'MooseX::AttributeHelpers::MethodProvider::Number', +__PACKAGE__->sugar( + method_provider => 'Number', shortcut => 'Number', ); no Moose; -no MooseX::AttributeHelpers::Sugar; 1; diff --git a/lib/MooseX/AttributeHelpers/String.pm b/lib/MooseX/AttributeHelpers/String.pm index 7ef8123..99cbb58 100644 --- a/lib/MooseX/AttributeHelpers/String.pm +++ b/lib/MooseX/AttributeHelpers/String.pm @@ -1,27 +1,24 @@ - package MooseX::AttributeHelpers::String; use Moose; -use MooseX::AttributeHelpers::Sugar; +use MooseX::AttributeHelpers::MethodProvider::String; extends 'MooseX::AttributeHelpers::Base'; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; -define_attribute_helper ( +__PACKAGE__->sugar( default_options => { is => 'rw', default => '', }, - helper_type => 'Str', - method_provider => 'MooseX::AttributeHelpers::MethodProvider::String', auto_provide => 1, + method_provider => 'String', shortcut => 'String', ); no Moose; -no MooseX::AttributeHelpers::Sugar; 1; diff --git a/t/001_basic_counter.t b/t/001_basic_counter.t index 1f7d760..cfba25d 100644 --- a/t/001_basic_counter.t +++ b/t/001_basic_counter.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 13; BEGIN { use_ok('MooseX::AttributeHelpers'); @@ -54,8 +54,6 @@ is($page->counter, 0, '... got the original value'); my $counter = $page->meta->get_attribute('counter'); isa_ok($counter, 'MooseX::AttributeHelpers::Counter'); -is($counter->helper_type, 'Num', '... got the expected helper type'); - is($counter->type_constraint->name, 'Int', '... got the expected type constraint'); is_deeply($counter->provides, { diff --git a/t/007_basic_string.t b/t/007_basic_string.t index eb54f1a..0b31d8b 100644 --- a/t/007_basic_string.t +++ b/t/007_basic_string.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 16; BEGIN { use_ok('MooseX::AttributeHelpers'); @@ -72,8 +72,6 @@ is($page->string, '', "clear"); my $string = $page->meta->get_attribute('string'); isa_ok($string, 'MooseX::AttributeHelpers::String'); -is($string->helper_type, 'Str', '... got the expected helper type'); - is($string->type_constraint->name, 'Str', '... got the expected type constraint'); is_deeply($string->provides, { diff --git a/t/011_counter_with_defaults.t b/t/011_counter_with_defaults.t index 37ed3bc..6de0470 100644 --- a/t/011_counter_with_defaults.t +++ b/t/011_counter_with_defaults.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 13; BEGIN { use_ok('MooseX::AttributeHelpers'); @@ -44,9 +44,7 @@ is($page->counter, 0, '... got the original value'); my $counter = $page->meta->get_attribute('counter'); isa_ok($counter, 'MooseX::AttributeHelpers::Counter'); -is($counter->helper_type, 'Num', '... got the expected helper type'); - -is($counter->type_constraint->name, 'Num', '... got the expected default type constraint'); +is($counter->type_constraint->name, 'Int', '... got the expected default type constraint'); is_deeply($counter->provides, { inc => 'inc_counter',