Methods for incrementing and decrementing a counter attribute.
+=item L<String|MooseX::AttributeHelpers::String>
+
+Common string operations.
+
=item L<Collection::Hash|MooseX::AttributeHelpers::Collection::Hash>
Common methods for hash references.
Common list methods for array references.
+=item L<Collection::Bag|MooseX::AttributeHelpers::Collection::Bag>
+
+Mathematical bags.
+
+=item L<Collection::ImmutableHash|MooseX::AttributeHelpers::Collection::ImmutableHash>
+
+Hashes with no change methods.
+
=back
=head1 CAVEAT
=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_provides>
-
-=back
+This is currently a sort of placeholder for future functionality. All
+Collection helpers are encouraged to inherit from it, in case it does
+something in the future.
=head1 BUGS
=head1 DESCRIPTION
-This module provides a simple counter attribute, which can be
-incremented and decremeneted.
+This module provides a simple counter attribute, which can be incremented and
+decremented. It is important to note that all those methods do in place
+modification of the value stored in the attribute.
If your attribute definition does not include any of I<is>, I<isa>,
I<default> or I<provides> but does use the C<Counter> metaclass,
has 'foo' => (metaclass => 'Counter');
$obj->inc_foo;
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
=head1 PROVIDED METHODS
-It is important to note that all those methods do in place
-modification of the value stored in the attribute.
-
-=over 4
-
-=item I<inc>
-
-Increments the value stored in this slot by 1.
-
-=item I<dec>
-
-Decrements the value stored in this slot by 1.
-
-=item I<reset>
-
-Resets the value stored in this slot to it's default value.
-
-=back
+The methods for this metaclass are provided by
+L<MooseX::AttributeHelpers::MethodProvider::Counter>.
=head1 BUGS
package MooseX::AttributeHelpers::MethodProvider::Array;
use Moose::Role;
+use MooseX::AttributeHelpers::Collection::TypeCheck;
our $VERSION = '0.05';
our $AUTHORITY = 'cpan:STEVAN';
sub push : method {
my ($attr, $reader, $writer) = @_;
-
- if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
- my $container_type_constraint = $attr->type_constraint->type_parameter;
- return sub {
- my $instance = CORE::shift;
- $container_type_constraint->check($_)
- || confess "Value " . ($_||'undef') . " did not pass container type constraint"
- foreach @_;
- CORE::push @{$reader->($instance)} => @_;
- };
- }
- else {
- return sub {
- my $instance = CORE::shift;
- CORE::push @{$reader->($instance)} => @_;
- };
- }
+ return type_check($attr, sub {@_[1,$#_]}, sub {
+ my $self = shift;
+ CORE::push(@{ $reader->($self) }, @_);
+ });
}
sub pop : method {
my ($attr, $reader, $writer) = @_;
- return sub {
- CORE::pop @{$reader->($_[0])}
- };
+ return sub { CORE::pop(@{ $reader->($_[0]) }) };
}
sub unshift : method {
my ($attr, $reader, $writer) = @_;
- if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
- my $container_type_constraint = $attr->type_constraint->type_parameter;
- return sub {
- my $instance = CORE::shift;
- $container_type_constraint->check($_)
- || confess "Value " . ($_||'undef') . " did not pass container type constraint"
- foreach @_;
- CORE::unshift @{$reader->($instance)} => @_;
- };
- }
- else {
- return sub {
- my $instance = CORE::shift;
- CORE::unshift @{$reader->($instance)} => @_;
- };
- }
+ return type_check($attr, sub {@_[1,$#_]}, sub {
+ my $self = shift;
+ CORE::unshift(@{ $reader->($self) }, @_);
+ });
}
sub shift : method {
my ($attr, $reader, $writer) = @_;
return sub {
- CORE::shift @{$reader->($_[0])}
+ CORE::shift(@{ $reader->($_[0]) });
};
}
sub get : method {
my ($attr, $reader, $writer) = @_;
return sub {
- $reader->($_[0])->[$_[1]]
+ my $self = shift;
+ return @{ $reader->($self) }[@_];
};
}
sub set : method {
my ($attr, $reader, $writer) = @_;
- if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
- my $container_type_constraint = $attr->type_constraint->type_parameter;
- return sub {
- ($container_type_constraint->check($_[2]))
- || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
- $reader->($_[0])->[$_[1]] = $_[2]
- };
- }
- else {
- return sub {
- $reader->($_[0])->[$_[1]] = $_[2]
- };
- }
+ return type_check($attr, sub {@_[2,$#_]}, sub {
+ my ($self, $index, @values) = @_;
+ my @indexes = (ref $index eq 'ARRAY' ? @$index : ($index));
+ @{ $reader->($self) }[@indexes] = @values;
+ });
}
sub clear : method {
my ($attr, $reader, $writer) = @_;
- return sub {
- @{$reader->($_[0])} = ()
- };
+ return sub { @{ $reader->($_[0]) } = () };
}
sub delete : method {
my ($attr, $reader, $writer) = @_;
return sub {
- CORE::splice @{$reader->($_[0])}, $_[1], 1;
- }
+ CORE::splice(@{ $reader->($_[0]) }, $_[1], $_[2] || 1);
+ };
}
sub insert : method {
my ($attr, $reader, $writer) = @_;
- if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
- my $container_type_constraint = $attr->type_constraint->type_parameter;
- return sub {
- ($container_type_constraint->check($_[2]))
- || confess "Value " . ($_[2]||'undef') . " did not pass container type constraint";
- CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
- };
- }
- else {
- return sub {
- CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
- };
- }
+ return type_contraint($attr, sub {@_[2,$#_]}, sub {
+ my ($self, $index, @values) = @_;
+ CORE::splice(@{ $reader->($self) }, $index, 0, @values);
+ });
}
1;
This is a role which provides the method generators for
L<MooseX::AttributeHelpers::Collection::Array>.
-=head1 METHODS
+=head1 PROVIDED METHODS
+
+This module consumes L<MooseX::AttributeHelpers::MethodProvider::List>, and so
+provides all of its methods as well. All methods work when multiple indexes
+are supplied - special cases are noted.
=over 4
-=item B<meta>
+=item B<get(@indexes)>
-=back
+Behaves just like indexing an arrayref: returns the items indexed by the
+supplied arguments (i.e. C<$self->get_my_stuff(1,2,3)> means
+C<@{$aref}[1,2,3]>).
-=head1 PROVIDED METHODS
+=item B<set($index, $value)>
-This module also consumes the B<List> method providers, to
-see those provied methods, refer to that documentation.
+=item B<set([$indexes], @values)>
-=over 4
-
-=item B<get>
+This is just like assigning to an arrayref, except that an arrayref lets you
+assign multiple indexes at once with no strange syntax. You can do that with
+this set as well, but the first argument should be an arrayref of the keys you
+want to assign to. (e.g. C<$self->set_aref([1,2,3], qw(foo bar baz))>)
=item B<pop>
-=item B<push>
+L<perlfunc/pop>
-=item B<set>
+=item B<push($item)>
+
+L<perlfunc/push>
=item B<shift>
-=item B<unshift>
+L<perlfunc/shift>
+
+=item B<unshift($item)>
+
+L<perlfunc/unshift>
=item B<clear>
-=item B<delete>
+Deletes all items from the array.
+
+=item B<delete($index, $length)>
+
+Deletes $length (default: 1) items from the array at $index.
+
+=item B<insert($index, @items)>
-=item B<insert>
+Inserts @items into list at $index.
=back
=head1 DESCRIPTION
This is a role which provides the method generators for
-L<MooseX::AttributeHelpers::Collection::Bag>.
-
-This role is composed from the
-L<MooseX::AttributeHelpers::Collection::ImmutableHash> role.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=back
+L<MooseX::AttributeHelpers::Collection::Bag>. It also consumes
+L<MooseX::AttributeHelpers::Collection::ImmutableHash>, and thus provides all
+of its methods asw well.
=head1 PROVIDED METHODS
=over 4
-=item B<count>
-
=item B<delete>
-=item B<empty>
-
-=item B<exists>
-
-=item B<get>
-
-=item B<keys>
+Remove the supplied key from the bag.
=item B<add>
-=item B<reset>
+Adds one to the value stored at the supplied key.
-=item B<values>
+=item B<reset>
-=item B<kv>
+Sets the value at the supplied key to zero.
=back
This is a role which provides the method generators for
L<MooseX::AttributeHelpers::Counter>.
-=head1 METHODS
+=head1 PROVIDED METHODS
=over 4
-=item B<meta>
+=item I<inc>
-=back
+Increments the value stored in this slot by 1.
-=head1 PROVIDED METHODS
-
-=over 4
+=item I<dec>
-=item B<inc>
+Decrements the value stored in this slot by 1.
-=item B<dec>
+=item I<reset>
-=item B<reset>
+Resets the value stored in this slot to its default value.
=back
package MooseX::AttributeHelpers::MethodProvider::Hash;
use Moose::Role;
+use MooseX::AttributeHelpers::Collection::TypeCheck;
our $VERSION = '0.04';
our $AUTHORITY = 'cpan:STEVAN';
sub set : method {
my ($attr, $reader, $writer) = @_;
- if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
- my $container_type_constraint = $attr->type_constraint->type_parameter;
- return sub {
- my ( $self, @kvp ) = @_;
-
- my ( @keys, @values );
-
- while ( @kvp ) {
- my ( $key, $value ) = ( shift(@kvp), shift(@kvp) );
- ($container_type_constraint->check($value))
- || confess "Value " . ($value||'undef') . " did not pass container type constraint";
- push @keys, $key;
- push @values, $value;
+ type_check(
+ $attr,
+ sub {
+ my ($self, %pairs) = @_;
+ return (values %pairs);
+ },
+ sub {
+ my ($self, @pairs) = @_;
+ my $hash = $reader->($self);
+ while (@pairs) {
+ my $key = shift(@pairs);
+ my $value = shift(@pairs);
+ $hash->{$key} = $value;
}
-
- if ( @values > 1 ) {
- @{ $reader->($self) }{@keys} = @values;
- } else {
- $reader->($self)->{$keys[0]} = $values[0];
- }
- };
- }
- else {
- return sub {
- if ( @_ == 3 ) {
- $reader->($_[0])->{$_[1]} = $_[2]
- } else {
- my ( $self, @kvp ) = @_;
- my ( @keys, @values );
-
- while ( @kvp ) {
- push @keys, shift @kvp;
- push @values, shift @kvp;
- }
-
- @{ $reader->($_[0]) }{@keys} = @values;
- }
- };
- }
+ },
+ );
}
sub clear : method {
=head1 DESCRIPTION
This is a role which provides the method generators for
-L<MooseX::AttributeHelpers::Collection::Hash>.
-
-This role is composed from the
-L<MooseX::AttributeHelpers::Collection::ImmutableHash> role.
-
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=back
+L<MooseX::AttributeHelpers::Collection::Hash>. It consumes
+L<MooseX::AttributeHelpers::MethodProvider::ImmutableHash>, and thus
+provides all its methods as wel.
=head1 PROVIDED METHODS
=item B<count>
-=item B<delete>
+Returns the number of items in the hash.
-=item B<empty>
+=item B<delete(@keys)>
-=item B<clear>
+Deletes the specified keys from the hash.
-=item B<exists>
-
-=item B<get>
+=item B<clear>
-=item B<keys>
+Deletes all keys from the hash.
=item B<set>
-=item B<values>
-
-=item B<kv>
+Sets the specified keys to the specified values. You can specify several of
+these at once, in key => value order.
=back
sub exists : method {
my ($attr, $reader, $writer) = @_;
- return sub { CORE::exists $reader->($_[0])->{$_[1]} ? 1 : 0 };
+ return sub { CORE::exists $reader->($_[0])->{$_[1]} };
}
sub get : method {
my ($attr, $reader, $writer) = @_;
- return sub {
- if ( @_ == 2 ) {
- $reader->($_[0])->{$_[1]}
- } else {
- my ( $self, @keys ) = @_;
- @{ $reader->($self) }{@keys}
- }
+ return sub {
+ my ($self, @keys) = @_;
+ @{ $reader->($self) }{@keys}
};
}
return sub { scalar CORE::keys %{$reader->($_[0])} };
}
+# Deprecated. The author was thinking backwardsly when this was written.
sub empty : method {
my ($attr, $reader, $writer) = @_;
return sub { scalar CORE::keys %{$reader->($_[0])} ? 1 : 0 };
}
+sub is_empty : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub { CORE::keys %{$reader->($_[0])} == 0 };
+}
+
+sub has_items : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub { CORE::keys %{$reader->($_[0])} > 0 };
+}
+
1;
__END__
This is a role which provides the method generators for
L<MooseX::AttributeHelpers::Collection::ImmutableHash>.
-=head1 METHODS
+=head1 PROVIDED METHODS
=over 4
-=item B<meta>
+=item B<count>
-=back
+Returns the number of items in the hash.
-=head1 PROVIDED METHODS
+=item B<empty>
-=over 4
+DEPRECATED. This was a misleading name for what it does (returns a boolean
+indicating whether the hash is NOT empty), but we're keeping it for backwards
+compatibility. Do not use it in new code. Use is_empty or has_items instead,
+depending on what you meant.
-=item B<count>
+=item B<is_empty>
-=item B<empty>
+Returns a boolean which is true if and only if the hash has no items in it.
+
+=item B<has_items>
+
+Returns a boolean which is true if and only if the hash has at least one item.
=item B<exists>
-=item B<get>
+L<perlfunc/exists>
+
+=item B<get(@keys)>
+
+Gets the values specified by @keys from the hash.
=item B<keys>
+L<perlfunc/keys>
+
=item B<values>
+L<perlfunc/values>
+
=item B<kv>
+Returns a list of arrayrefs, each of which is a key => value pair mapping.
+
=back
=head1 BUGS
sub count : method {
my ($attr, $reader, $writer) = @_;
- return sub {
- scalar @{$reader->($_[0])}
- };
+ return sub { scalar @{$reader->($_[0])} };
}
+# Deprecated. The author was thinking backwardsly when this was written.
sub empty : method {
my ($attr, $reader, $writer) = @_;
- return sub {
- scalar @{$reader->($_[0])} ? 1 : 0
- };
+ return sub { scalar @{$reader->($_[0])} ? 1 : 0 };
+}
+
+sub is_empty : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub { @{ $reader->($_[0]) } == 0 };
+}
+
+sub has_items : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub { @{ $reader->($_[0]) } > 0 };
}
sub find : method {
This is a role which provides the method generators for
L<MooseX::AttributeHelpers::Collection::List>.
-=head1 METHODS
+=head1 PROVIDED METHODS
=over 4
-=item B<meta>
+=item B<count>
-=back
+Returns the number of items in the list.
-=head1 PROVIDED METHODS
+=item B<empty>
-=over 4
+DEPRECATED. This was a misleading name for what it does (returns a boolean
+indicating whether the list is NOT empty), but we're keeping it for backwards
+compatibility. Do not use it in new code. Use is_empty or has_items instead,
+depending on what you meant.
-=item B<count>
+=item B<is_empty>
-=item B<empty>
+Returns a boolean which is true if and only if the list has no items in it.
+
+=item B<has_items>
-=item B<find>
+Returns a boolean which is true if and only if the list has at least one item.
+
+=item B<find($predicate)>
+
+Returns the first item in the list that satisfies $predicate.
=item B<grep>
+L<perlfunc/grep>
+
=item B<map>
+L<perlfunc/map>
+
=back
=head1 BUGS
div => '/',
mod => '%',
);
+
foreach my $method (keys %ops)
{
my $s = $ops{$method};
=head1 PROVIDED METHODS
-It is important to note that all those methods do in place modification of the
-value stored in the attribute. All methods but 'set' are plain mathematical
-operators, as in $current_value = $current_value I<op>$argument, where I<op> is
-the operator listed next to the method name.
+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.
=over 4
-=item B<add>: +
+=item B<add> +
-=item B<sub>: -
+=item B<sub> -
-=item B<mul>: *
+=item B<mul> *
-=item B<div>: /
+=item B<div> /
-=item B<mod>: %
+=item B<mod> %
-=item B<abs>: |$val|, or $val = abs($value).
+=item B<abs> |$val|, or $val = abs($value).
-=item B<set>:
+=item B<set>
A way to set the value instead of 'setter' or 'is => "rw"'. This method is
provided for convenience.
This is a role which provides the method generators for
L<MooseX::AttributeHelpers::String>.
-=head1 METHODS
+=head1 PROVIDED METHODS
+
+It should be noted that all methods modify attribute values in place.
=over 4
-=item B<meta>
+=item I<inc>
-=back
+Increments the value stored in this slot using the magical string autoincrement
+operator. Note that Perl doesn't provide analogeous behavior in C<-->, so
+C<dec> is not available.
-=head1 PROVIDED METHODS
+=item I<append> C<$string>
-=over 4
+Append a string, like C<.=>.
+
+=item I<prepend> C<$string>
+
+Prepend a string.
+
+=item I<replace> C<$pattern> C<$replacement>
+
+Performs a regexp substitution (L<perlop/s>). There is no way to provide the
+C<g> flag, but code references will be accepted for the replacement, causing
+the regex to be modified with a single C<e>. C</smxi> can be applied using the
+C<qr> operator.
-=item B<append>
+=item I<match> C<$pattern>
-=item B<prepend>
+Like I<replace> but without the replacement. Provided mostly for completeness.
-=item B<replace>
+=item C<chop>
-=item B<match>
+L<perlfunc/chop>
-=item B<chomp>
+=item C<chomp>
-=item B<chop>
+L<perlfunc/chomp>
-=item B<inc>
+=item C<clear>
-=item B<clear>
+Sets the string to the empty string (not the value passed to C<default>).
=back
=head1 DESCRIPTION
This provides a simple numeric attribute, which supports most of the
-basic math operations.
+basic math operations. It is important to note that all operations modify the
+value of the attribute in place.
=head1 METHOD PROVIDER
The methods for this metaclass are provided by
-L<MooseX::AttributeHelpers::MethodProvider::String>.
+L<MooseX::AttributeHelpers::MethodProvider::Number>.
=head1 BUGS
has 'foo' => (metaclass => 'String');
$obj->append_foo;
-=head1 METHODS
-
-=over 4
-
-=item B<meta>
-
-=back
-
=head1 PROVIDED METHODS
-It is important to note that all those methods do in place
-modification of the value stored in the attribute.
-
-=over 4
-
-=item I<inc>
-
-Increments the value stored in this slot using the magical string autoincrement
-operator. Note that Perl doesn't provide analogeous behavior in C<-->, so
-C<dec> is not available.
-
-=item I<append> C<$string>
-
-Append a string, like C<.=>.
-
-=item I<prepend> C<$string>
-
-Prepend a string.
-
-=item I<replace> C<$pattern> C<$replacement>
-
-Performs a regexp substitution (L<perlop/s>). There is no way to provide the
-C<g> flag, but code references will be accepted for the replacement, causing
-the regex to be modified with a single C<e>. C</smxi> can be applied using the
-C<qr> operator.
-
-=item I<match> C<$pattern>
-
-Like I<replace> but without the replacement. Provided mostly for completeness.
-
-=item C<chop>
-
-L<perlfunc/chop>
-
-=item C<chomp>
-
-L<perlfunc/chomp>
-
-=item C<clear>
-
-Sets the string to the empty string (not the value passed to C<default>).
-
-=back
+The methods for this metaclass are provided by
+L<MooseX::AttributeHelpers::MethodProvider::String>.
=head1 BUGS
=item B<define_attribute_helper>
The following parameters are accepted, and are used to override methods in
-the base class (see its documentation for details).
+the base class (see L<its documentation|MooseX::AttributeHelpers::Base> for
+details).
=item B<default_options> I<HashRef>
=back
-=head SHORTCUT
+=head1 SHORTCUT
For ease of use of the generated metaclasses, if you pass in a "shortcut"
parameter to define_attribute_helper, a class at
use strict;
use warnings;
-use Test::More tests => 51;
+use Test::More tests => 54;
use Test::Exception;
BEGIN {
isa => 'ArrayRef[Int]',
default => sub { [] },
provides => {
- 'push' => 'add_options',
- 'pop' => 'remove_last_option',
- 'shift' => 'remove_first_option',
- 'unshift' => 'insert_options',
- 'get' => 'get_option_at',
- 'set' => 'set_option_at',
- 'count' => 'num_options',
- 'empty' => 'has_options',
- 'clear' => 'clear_options',
+ 'push' => 'add_options',
+ 'pop' => 'remove_last_option',
+ 'shift' => 'remove_first_option',
+ 'unshift' => 'insert_options',
+ 'get' => 'get_option_at',
+ 'set' => 'set_option_at',
+ 'count' => 'num_options',
+ 'is_empty' => 'no_options',
+ 'has_items' => 'has_options',
+ 'clear' => 'clear_options',
}
);
}
num_options
clear_options
has_options
+ no_options
];
is_deeply($stuff->options, [10, 12], '... got options');
is_deeply($stuff->options, [], '... no options anymore');
-ok(!$stuff->has_options, '... no options');
+ok($stuff->no_options, '... no options');
is($stuff->num_options, 0, '... got no options');
lives_ok {
is_deeply($stuff->options, [1, 2, 3], '... got options now');
-ok($stuff->has_options, '... no options');
+ok($stuff->has_options, '... have options');
is($stuff->num_options, 3, '... got 3 options');
is($stuff->get_option_at(0), 1, '... get option at index 0');
$stuff->clear_options;
is_deeply( $stuff->options, [], "... clear options" );
+lives_ok {
+ $stuff->set_option_at([0..2], 10, 20, 30);
+} '... set multiple options';
+
+is_deeply(
+ [$stuff->get_option_at(0..2)],
+ [10,20,30],
+ '... and got what we set'
+);
+
## check some errors
dies_ok {
isa_ok($options, 'MooseX::AttributeHelpers::Collection::Array');
is_deeply($options->provides, {
- 'push' => 'add_options',
- 'pop' => 'remove_last_option',
- 'shift' => 'remove_first_option',
- 'unshift' => 'insert_options',
- 'get' => 'get_option_at',
- 'set' => 'set_option_at',
- 'count' => 'num_options',
- 'empty' => 'has_options',
- 'clear' => 'clear_options',
-}, '... got the right provies mapping');
+ 'push' => 'add_options',
+ 'pop' => 'remove_last_option',
+ 'shift' => 'remove_first_option',
+ 'unshift' => 'insert_options',
+ 'get' => 'get_option_at',
+ 'set' => 'set_option_at',
+ 'count' => 'num_options',
+ 'is_empty' => 'no_options',
+ 'has_items' => 'has_options',
+ 'clear' => 'clear_options',
+}, '... got the right provides mapping');
is($options->type_constraint->type_parameter, 'Int', '... got the right container type');
use strict;
use warnings;
-use Test::More tests => 32;
+use Test::More tests => 33;
use Test::Exception;
BEGIN {
isa => 'HashRef[Str]',
default => sub { {} },
provides => {
- 'set' => 'set_option',
- 'get' => 'get_option',
- 'empty' => 'has_options',
- 'count' => 'num_options',
- 'clear' => 'clear_options',
- 'delete' => 'delete_option',
+ 'set' => 'set_option',
+ 'get' => 'get_option',
+ 'has_items' => 'has_options',
+ 'is_empty' => 'no_options',
+ 'count' => 'num_options',
+ 'clear' => 'clear_options',
+ 'delete' => 'delete_option',
}
);
}
set_option
get_option
has_options
+ no_options
num_options
delete_option
clear_options
];
-ok(!$stuff->has_options, '... we have no options');
+ok($stuff->no_options, '... we have no options');
is($stuff->num_options, 0, '... we have no options');
is_deeply($stuff->options, {}, '... no options yet');
isa => 'ArrayRef[Int]',
default => sub { [] },
provides => {
- 'count' => 'num_options',
- 'empty' => 'has_options',
- 'map' => 'map_options',
- 'grep' => 'filter_options',
- 'find' => 'find_option',
+ 'count' => 'num_options',
+ 'has_items' => 'has_options',
+ 'map' => 'map_options',
+ 'grep' => 'filter_options',
+ 'find' => 'find_option',
}
);
}
isa_ok($options, 'MooseX::AttributeHelpers::Collection::List');
is_deeply($options->provides, {
- 'map' => 'map_options',
- 'grep' => 'filter_options',
- 'find' => 'find_option',
- 'count' => 'num_options',
- 'empty' => 'has_options',
-}, '... got the right provies mapping');
+ 'map' => 'map_options',
+ 'grep' => 'filter_options',
+ 'find' => 'find_option',
+ 'count' => 'num_options',
+ 'has_items' => 'has_options',
+}, '... got the right provides mapping');
is($options->type_constraint->type_parameter, 'Int', '... got the right container type');
use strict;
use warnings;
-use Test::More tests => 18;
+use Test::More tests => 19;
use Test::Exception;
BEGIN {
metaclass => 'Collection::Bag',
is => 'ro',
provides => {
- 'add' => 'add_word',
- 'get' => 'get_count_for',
- 'empty' => 'has_any_words',
- 'count' => 'num_words',
- 'delete' => 'delete_word',
+ 'add' => 'add_word',
+ 'get' => 'get_count_for',
+ 'has_items' => 'has_any_words',
+ 'is_empty' => 'has_no_words',
+ 'count' => 'num_words',
+ 'delete' => 'delete_word',
}
);
}
add_word
get_count_for
has_any_words
+ has_no_words
num_words
delete_word
];
-ok(!$stuff->has_any_words, '... we have no words');
+ok($stuff->has_no_words, '... we have no words');
is($stuff->num_words, 0, '... we have no words');
lives_ok {