This commit is contained in:
387
CPAN/Moose/Meta/Attribute/Native/Trait/Array.pm
Normal file
387
CPAN/Moose/Meta/Attribute/Native/Trait/Array.pm
Normal file
@@ -0,0 +1,387 @@
|
||||
package Moose::Meta::Attribute::Native::Trait::Array;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use Moose::Role;
|
||||
with 'Moose::Meta::Attribute::Native::Trait';
|
||||
|
||||
sub _helper_type { 'ArrayRef' }
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Helper trait for ArrayRef attributes
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Moose::Meta::Attribute::Native::Trait::Array - Helper trait for ArrayRef attributes
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2207
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
package Stuff;
|
||||
use Moose;
|
||||
|
||||
has 'options' => (
|
||||
traits => ['Array'],
|
||||
is => 'ro',
|
||||
isa => 'ArrayRef[Str]',
|
||||
default => sub { [] },
|
||||
handles => {
|
||||
all_options => 'elements',
|
||||
add_option => 'push',
|
||||
map_options => 'map',
|
||||
filter_options => 'grep',
|
||||
find_option => 'first',
|
||||
get_option => 'get',
|
||||
join_options => 'join',
|
||||
count_options => 'count',
|
||||
has_options => 'count',
|
||||
has_no_options => 'is_empty',
|
||||
sorted_options => 'sort',
|
||||
},
|
||||
);
|
||||
|
||||
no Moose;
|
||||
1;
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This trait provides native delegation methods for array references.
|
||||
|
||||
=head1 DEFAULT TYPE
|
||||
|
||||
If you don't provide an C<isa> value for your attribute, it will default to
|
||||
C<ArrayRef>.
|
||||
|
||||
=head1 PROVIDED METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item * B<count>
|
||||
|
||||
Returns the number of elements in the array.
|
||||
|
||||
$stuff = Stuff->new;
|
||||
$stuff->options( [ "foo", "bar", "baz", "boo" ] );
|
||||
|
||||
print $stuff->count_options; # prints 4
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<is_empty>
|
||||
|
||||
Returns a boolean value that is true when the array has no elements.
|
||||
|
||||
$stuff->has_no_options ? die "No options!\n" : print "Good boy.\n";
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<elements>
|
||||
|
||||
In list context, returns all of the elements of the array as a list.
|
||||
|
||||
In scalar context, returns the number of elements in the array.
|
||||
|
||||
my @options = $stuff->all_options;
|
||||
print "@options"; # prints "foo bar baz boo"
|
||||
print scalar $stuff->all_options; # prints 4
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<get($index)>
|
||||
|
||||
Returns an element of the array by its index. You can also use negative index
|
||||
numbers, just as with Perl's core array handling.
|
||||
|
||||
my $option = $stuff->get_option(1);
|
||||
print "$option\n"; # prints "bar"
|
||||
|
||||
If the specified element does not exist, this will return C<undef>.
|
||||
|
||||
This method accepts just one argument.
|
||||
|
||||
=item * B<pop>
|
||||
|
||||
Just like Perl's builtin C<pop>.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<push($value1, $value2, value3 ...)>
|
||||
|
||||
Just like Perl's builtin C<push>. Returns the number of elements in the new
|
||||
array.
|
||||
|
||||
This method accepts any number of arguments.
|
||||
|
||||
=item * B<shift>
|
||||
|
||||
Just like Perl's builtin C<shift>.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<unshift($value1, $value2, value3 ...)>
|
||||
|
||||
Just like Perl's builtin C<unshift>. Returns the number of elements in the new
|
||||
array.
|
||||
|
||||
This method accepts any number of arguments.
|
||||
|
||||
=item * B<splice($offset, $length, @values)>
|
||||
|
||||
Just like Perl's builtin C<splice>. In scalar context, this returns the last
|
||||
element removed, or C<undef> if no elements were removed. In list context,
|
||||
this returns all the elements removed from the array.
|
||||
|
||||
This method requires at least one argument.
|
||||
|
||||
=item * B<first( sub { ... } )>
|
||||
|
||||
This method returns the first matching item in the array, just like
|
||||
L<List::Util>'s C<first> function. The matching is done with a subroutine
|
||||
reference you pass to this method. The subroutine will be called against each
|
||||
element in the array until one matches or all elements have been checked.
|
||||
Each list element will be available to the sub in C<$_>.
|
||||
|
||||
my $found = $stuff->find_option( sub {/^b/} );
|
||||
print "$found\n"; # prints "bar"
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<first_index( sub { ... } )>
|
||||
|
||||
This method returns the index of the first matching item in the array, just
|
||||
like L<List::SomeUtils/first_index>. The matching is done with a
|
||||
subroutine reference you pass to this method. The subroutine will be called
|
||||
against each element in the array until one matches or all elements have been
|
||||
checked. Each list element will be available to the sub in C<$_>.
|
||||
If no match is made, -1 is returned.
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<grep( sub { ... } )>
|
||||
|
||||
This method returns every element matching a given criteria, just like Perl's
|
||||
core C<grep> function. This method requires a subroutine which implements the
|
||||
matching logic; each list element will be available to the sub in C<$_>.
|
||||
|
||||
my @found = $stuff->filter_options( sub {/^b/} );
|
||||
print "@found\n"; # prints "bar baz boo"
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<map( sub { ... } )>
|
||||
|
||||
This method transforms every element in the array and returns a new array,
|
||||
just like Perl's core C<map> function. This method requires a subroutine which
|
||||
implements the transformation; each list element will be available to the sub
|
||||
in C<$_>.
|
||||
|
||||
my @mod_options = $stuff->map_options( sub { $_ . "-tag" } );
|
||||
print "@mod_options\n"; # prints "foo-tag bar-tag baz-tag boo-tag"
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<reduce( sub { ... } )>
|
||||
|
||||
This method turns an array into a single value, by passing a function the
|
||||
value so far and the next value in the array, just like L<List::Util>'s
|
||||
C<reduce> function. The reducing is done with a subroutine reference you pass
|
||||
to this method; each list element will be available to the sub in C<$_>.
|
||||
|
||||
my $found = $stuff->reduce_options( sub { $_[0] . $_[1] } );
|
||||
print "$found\n"; # prints "foobarbazboo"
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<sort>
|
||||
|
||||
=item * B<sort( sub { ... } )>
|
||||
|
||||
Returns the elements of the array (not an array reference) in sorted order,
|
||||
or, like C<elements>, returns the number of elements in the array in scalar context.
|
||||
|
||||
You can provide an optional subroutine reference to sort with (as you can with
|
||||
Perl's core C<sort> function). However, instead of using C<$a> and C<$b> in
|
||||
this subroutine, you will need to use C<$_[0]> and C<$_[1]>.
|
||||
|
||||
# ascending ASCIIbetical
|
||||
my @sorted = $stuff->sort_options();
|
||||
|
||||
# Descending alphabetical order
|
||||
my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } );
|
||||
print "@sorted_options\n"; # prints "foo boo baz bar"
|
||||
|
||||
This method accepts a single argument.
|
||||
|
||||
=item * B<sort_in_place>
|
||||
|
||||
=item * B<sort_in_place( sub { ... } )>
|
||||
|
||||
Sorts the array I<in place>, modifying the value of the attribute.
|
||||
|
||||
You can provide an optional subroutine reference to sort with (as you can with
|
||||
Perl's core C<sort> function). However, instead of using C<$a> and C<$b>, you
|
||||
will need to use C<$_[0]> and C<$_[1]> instead.
|
||||
|
||||
This method does not define a return value.
|
||||
|
||||
This method accepts a single argument.
|
||||
|
||||
=item * B<shuffle>
|
||||
|
||||
Returns the elements of the array in random order, like C<shuffle> from
|
||||
L<List::Util>.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<uniq>
|
||||
|
||||
Returns the array with all duplicate elements removed, like L<List::Util/uniq>.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<join($str)>
|
||||
|
||||
Joins every element of the array using the separator given as argument, just
|
||||
like Perl's core C<join> function.
|
||||
|
||||
my $joined = $stuff->join_options(':');
|
||||
print "$joined\n"; # prints "foo:bar:baz:boo"
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<set($index, $value)>
|
||||
|
||||
Given an index and a value, sets the specified array element's value.
|
||||
|
||||
This method returns the value at C<$index> after the set.
|
||||
|
||||
This method requires two arguments.
|
||||
|
||||
=item * B<delete($index)>
|
||||
|
||||
Removes the element at the given index from the array.
|
||||
|
||||
This method returns the deleted value. Note that if no value exists, it will
|
||||
return C<undef>.
|
||||
|
||||
This method requires one argument.
|
||||
|
||||
=item * B<insert($index, $value)>
|
||||
|
||||
Inserts a new element into the array at the given index.
|
||||
|
||||
This method returns the new value at C<$index>.
|
||||
|
||||
This method requires two arguments.
|
||||
|
||||
=item * B<clear>
|
||||
|
||||
Empties the entire array, like C<@array = ()>.
|
||||
|
||||
This method does not define a return value.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<accessor($index)>
|
||||
|
||||
=item * B<accessor($index, $value)>
|
||||
|
||||
This method provides a get/set accessor for the array, based on array indexes.
|
||||
If passed one argument, it returns the value at the specified index. If
|
||||
passed two arguments, it sets the value of the specified index.
|
||||
|
||||
When called as a setter, this method returns the new value at C<$index>.
|
||||
|
||||
This method accepts one or two arguments.
|
||||
|
||||
=item * B<natatime($n)>
|
||||
|
||||
=item * B<natatime($n, $code)>
|
||||
|
||||
This method returns an iterator which, on each call, returns C<$n> more items
|
||||
from the array, in order, like L<List::SomeUtils/natatime>.
|
||||
|
||||
If you pass a coderef as the second argument, then this code ref will be
|
||||
called on each group of C<$n> elements in the array until the array is
|
||||
exhausted.
|
||||
|
||||
This method accepts one or two arguments.
|
||||
|
||||
=item * B<shallow_clone>
|
||||
|
||||
This method returns a shallow clone of the array reference. The return value
|
||||
is a reference to a new array with the same elements. It is I<shallow>
|
||||
because any elements that were references in the original will be the I<same>
|
||||
references in the clone.
|
||||
|
||||
=back
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
See L<Moose/BUGS> for details on reporting bugs.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
146
CPAN/Moose/Meta/Attribute/Native/Trait/Bool.pm
Normal file
146
CPAN/Moose/Meta/Attribute/Native/Trait/Bool.pm
Normal file
@@ -0,0 +1,146 @@
|
||||
package Moose::Meta::Attribute::Native::Trait::Bool;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use Moose::Role;
|
||||
with 'Moose::Meta::Attribute::Native::Trait';
|
||||
|
||||
sub _helper_type { 'Bool' }
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Helper trait for Bool attributes
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Moose::Meta::Attribute::Native::Trait::Bool - Helper trait for Bool attributes
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2207
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
package Room;
|
||||
use Moose;
|
||||
|
||||
has 'is_lit' => (
|
||||
traits => ['Bool'],
|
||||
is => 'rw',
|
||||
isa => 'Bool',
|
||||
default => 0,
|
||||
handles => {
|
||||
illuminate => 'set',
|
||||
darken => 'unset',
|
||||
flip_switch => 'toggle',
|
||||
is_dark => 'not',
|
||||
},
|
||||
);
|
||||
|
||||
my $room = Room->new();
|
||||
$room->illuminate; # same as $room->is_lit(1);
|
||||
$room->darken; # same as $room->is_lit(0);
|
||||
$room->flip_switch; # same as $room->is_lit(not $room->is_lit);
|
||||
return $room->is_dark; # same as !$room->is_lit
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This trait provides native delegation methods for boolean values. A boolean is
|
||||
a scalar which can be C<1>, C<0>, C<"">, or C<undef>.
|
||||
|
||||
=head1 DEFAULT TYPE
|
||||
|
||||
If you don't provide an C<isa> value for your attribute, it will default to
|
||||
C<Bool>.
|
||||
|
||||
=head1 PROVIDED METHODS
|
||||
|
||||
None of these methods accept arguments.
|
||||
|
||||
=over 4
|
||||
|
||||
=item * B<set>
|
||||
|
||||
Sets the value to C<1> and returns C<1>.
|
||||
|
||||
=item * B<unset>
|
||||
|
||||
Set the value to C<0> and returns C<0>.
|
||||
|
||||
=item * B<toggle>
|
||||
|
||||
Toggles the value. If it's true, set to false, and vice versa.
|
||||
|
||||
Returns the new value.
|
||||
|
||||
=item * B<not>
|
||||
|
||||
Equivalent of 'not C<$value>'.
|
||||
|
||||
=back
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
See L<Moose/BUGS> for details on reporting bugs.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
129
CPAN/Moose/Meta/Attribute/Native/Trait/Code.pm
Normal file
129
CPAN/Moose/Meta/Attribute/Native/Trait/Code.pm
Normal file
@@ -0,0 +1,129 @@
|
||||
package Moose::Meta::Attribute::Native::Trait::Code;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use Moose::Role;
|
||||
with 'Moose::Meta::Attribute::Native::Trait';
|
||||
|
||||
sub _helper_type { 'CodeRef' }
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Helper trait for CodeRef attributes
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Moose::Meta::Attribute::Native::Trait::Code - Helper trait for CodeRef attributes
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2207
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
package Foo;
|
||||
use Moose;
|
||||
|
||||
has 'callback' => (
|
||||
traits => ['Code'],
|
||||
is => 'ro',
|
||||
isa => 'CodeRef',
|
||||
default => sub {
|
||||
sub { print "called" }
|
||||
},
|
||||
handles => {
|
||||
call => 'execute',
|
||||
},
|
||||
);
|
||||
|
||||
my $foo = Foo->new;
|
||||
$foo->call; # prints "called"
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This trait provides native delegation methods for code references.
|
||||
|
||||
=head1 DEFAULT TYPE
|
||||
|
||||
If you don't provide an C<isa> value for your attribute, it will default to
|
||||
C<CodeRef>.
|
||||
|
||||
=head1 PROVIDED METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item * B<execute(@args)>
|
||||
|
||||
Calls the coderef with the given args.
|
||||
|
||||
=item * B<execute_method(@args)>
|
||||
|
||||
Calls the coderef with the instance as invocant and given args.
|
||||
|
||||
=back
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
See L<Moose/BUGS> for details on reporting bugs.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
157
CPAN/Moose/Meta/Attribute/Native/Trait/Counter.pm
Normal file
157
CPAN/Moose/Meta/Attribute/Native/Trait/Counter.pm
Normal file
@@ -0,0 +1,157 @@
|
||||
package Moose::Meta::Attribute::Native::Trait::Counter;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use Moose::Role;
|
||||
with 'Moose::Meta::Attribute::Native::Trait';
|
||||
|
||||
sub _helper_type { 'Num' }
|
||||
sub _root_types { 'Num', 'Int' }
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Helper trait for Int attributes which represent counters
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for Int attributes which represent counters
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2207
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
package MyHomePage;
|
||||
use Moose;
|
||||
|
||||
has 'counter' => (
|
||||
traits => ['Counter'],
|
||||
is => 'ro',
|
||||
isa => 'Num',
|
||||
default => 0,
|
||||
handles => {
|
||||
inc_counter => 'inc',
|
||||
dec_counter => 'dec',
|
||||
reset_counter => 'reset',
|
||||
},
|
||||
);
|
||||
|
||||
my $page = MyHomePage->new();
|
||||
$page->inc_counter; # same as $page->counter( $page->counter + 1 );
|
||||
$page->dec_counter; # same as $page->counter( $page->counter - 1 );
|
||||
|
||||
my $count_by_twos = 2;
|
||||
$page->inc_counter($count_by_twos);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This trait provides native delegation methods for counters. A counter can be
|
||||
any sort of number (integer or not). The delegation methods allow you to
|
||||
increment, decrement, or reset the value.
|
||||
|
||||
=head1 DEFAULT TYPE
|
||||
|
||||
If you don't provide an C<isa> value for your attribute, it will default to
|
||||
C<Num>.
|
||||
|
||||
=head1 PROVIDED METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item * B<set($value)>
|
||||
|
||||
Sets the counter to the specified value and returns the new value.
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<inc>
|
||||
|
||||
=item * B<inc($arg)>
|
||||
|
||||
Increases the attribute value by the amount of the argument, or by 1 if no
|
||||
argument is given. This method returns the new value.
|
||||
|
||||
This method accepts a single argument.
|
||||
|
||||
=item * B<dec>
|
||||
|
||||
=item * B<dec($arg)>
|
||||
|
||||
Decreases the attribute value by the amount of the argument, or by 1 if no
|
||||
argument is given. This method returns the new value.
|
||||
|
||||
This method accepts a single argument.
|
||||
|
||||
=item * B<reset>
|
||||
|
||||
Resets the value stored in this slot to its default value, and returns the new
|
||||
value.
|
||||
|
||||
=back
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
See L<Moose/BUGS> for details on reporting bugs.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
227
CPAN/Moose/Meta/Attribute/Native/Trait/Hash.pm
Normal file
227
CPAN/Moose/Meta/Attribute/Native/Trait/Hash.pm
Normal file
@@ -0,0 +1,227 @@
|
||||
package Moose::Meta::Attribute::Native::Trait::Hash;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use Moose::Role;
|
||||
with 'Moose::Meta::Attribute::Native::Trait';
|
||||
|
||||
sub _helper_type { 'HashRef' }
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Helper trait for HashRef attributes
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef attributes
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2207
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
package Stuff;
|
||||
use Moose;
|
||||
|
||||
has 'options' => (
|
||||
traits => ['Hash'],
|
||||
is => 'ro',
|
||||
isa => 'HashRef[Str]',
|
||||
default => sub { {} },
|
||||
handles => {
|
||||
set_option => 'set',
|
||||
get_option => 'get',
|
||||
has_no_options => 'is_empty',
|
||||
num_options => 'count',
|
||||
delete_option => 'delete',
|
||||
option_pairs => 'kv',
|
||||
},
|
||||
);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This trait provides native delegation methods for hash references.
|
||||
|
||||
=head1 PROVIDED METHODS
|
||||
|
||||
=head2 get($key, $key2, $key3...)
|
||||
|
||||
Returns values from the hash.
|
||||
|
||||
In list context it returns a list of values in the hash for the given keys. In
|
||||
scalar context it returns the value for the last key specified.
|
||||
|
||||
This method requires at least one argument.
|
||||
|
||||
=head2 set($key =E<gt> $value, $key2 =E<gt> $value2...)
|
||||
|
||||
Sets the elements in the hash to the given values. It returns the new values
|
||||
set for each key, in the same order as the keys passed to the method.
|
||||
|
||||
This method requires at least two arguments, and expects an even number of
|
||||
arguments.
|
||||
|
||||
=head2 delete($key, $key2, $key3...)
|
||||
|
||||
Removes the elements with the given keys.
|
||||
|
||||
In list context it returns a list of values in the hash for the deleted
|
||||
keys. In scalar context it returns the value for the last key specified.
|
||||
|
||||
=head2 keys
|
||||
|
||||
Returns the list of keys in the hash.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=head2 exists($key)
|
||||
|
||||
Returns true if the given key is present in the hash.
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=head2 defined($key)
|
||||
|
||||
Returns true if the value of a given key is defined.
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=head2 values
|
||||
|
||||
Returns the list of values in the hash.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=head2 kv
|
||||
|
||||
Returns the key/value pairs in the hash as an array of array references.
|
||||
|
||||
for my $pair ( $object->option_pairs ) {
|
||||
print "$pair->[0] = $pair->[1]\n";
|
||||
}
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=head2 elements
|
||||
|
||||
In list context, this returns the key/value pairs in the hash.
|
||||
|
||||
In scalar context, this returns the count of keys plus values. In other words,
|
||||
it's the same as L<keys> times two.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=head2 clear
|
||||
|
||||
Resets the hash to an empty value, like C<%hash = ()>.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=head2 count
|
||||
|
||||
Returns the number of elements in the hash. Also useful to check for a nonempty hash, because C<count> returns a true (nonzero) value if there is something in the hash:
|
||||
C<< has_options => 'count' >>.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=head2 is_empty
|
||||
|
||||
If the hash is populated, returns false. Otherwise, returns true.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=head2 accessor($key)
|
||||
|
||||
=head2 accessor($key, $value)
|
||||
|
||||
If passed one argument, returns the value of the specified key. If passed two
|
||||
arguments, sets the value of the specified key.
|
||||
|
||||
When called as a setter, this method returns the value that was set.
|
||||
|
||||
=head2 shallow_clone
|
||||
|
||||
This method returns a shallow clone of the hash reference. The return value
|
||||
is a reference to a new hash with the same keys and values. It is I<shallow>
|
||||
because any values that were references in the original will be the I<same>
|
||||
references in the clone.
|
||||
|
||||
=head2 Why no C<each>?
|
||||
|
||||
We have deliberately omitted a method for C<each>, due to its stateful
|
||||
interaction with the hash iterator. Using C<keys> or C<kv> is much safer.
|
||||
|
||||
=head2 Moose::Meta::Attribute->meta
|
||||
|
||||
This will return a L<Class::MOP::Class> instance for this class.
|
||||
|
||||
It should also be noted that L<Class::MOP> will actually bootstrap
|
||||
this module by installing a number of attribute meta-objects into its
|
||||
metaclass.
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
See L<Moose/BUGS> for details on reporting bugs.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
155
CPAN/Moose/Meta/Attribute/Native/Trait/Number.pm
Normal file
155
CPAN/Moose/Meta/Attribute/Native/Trait/Number.pm
Normal file
@@ -0,0 +1,155 @@
|
||||
package Moose::Meta::Attribute::Native::Trait::Number;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use Moose::Role;
|
||||
with 'Moose::Meta::Attribute::Native::Trait';
|
||||
|
||||
sub _helper_type { 'Num' }
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Helper trait for Num attributes
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Moose::Meta::Attribute::Native::Trait::Number - Helper trait for Num attributes
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2207
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
package Real;
|
||||
use Moose;
|
||||
|
||||
has 'integer' => (
|
||||
traits => ['Number'],
|
||||
is => 'ro',
|
||||
isa => 'Num',
|
||||
default => 5,
|
||||
handles => {
|
||||
set => 'set',
|
||||
add => 'add',
|
||||
sub => 'sub',
|
||||
mul => 'mul',
|
||||
div => 'div',
|
||||
mod => 'mod',
|
||||
abs => 'abs',
|
||||
},
|
||||
);
|
||||
|
||||
my $real = Real->new();
|
||||
$real->add(5); # same as $real->integer($real->integer + 5);
|
||||
$real->sub(2); # same as $real->integer($real->integer - 2);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This trait provides native delegation methods for numbers. All of the
|
||||
operations correspond to arithmetic operations like addition or
|
||||
multiplication.
|
||||
|
||||
=head1 DEFAULT TYPE
|
||||
|
||||
If you don't provide an C<isa> value for your attribute, it will default to
|
||||
C<Num>.
|
||||
|
||||
=head1 PROVIDED METHODS
|
||||
|
||||
All of these methods modify the attribute's value in place. All methods return
|
||||
the new value.
|
||||
|
||||
=over 4
|
||||
|
||||
=item * B<add($value)>
|
||||
|
||||
Adds the current value of the attribute to C<$value>.
|
||||
|
||||
=item * B<sub($value)>
|
||||
|
||||
Subtracts C<$value> from the current value of the attribute.
|
||||
|
||||
=item * B<mul($value)>
|
||||
|
||||
Multiplies the current value of the attribute by C<$value>.
|
||||
|
||||
=item * B<div($value)>
|
||||
|
||||
Divides the current value of the attribute by C<$value>.
|
||||
|
||||
=item * B<mod($value)>
|
||||
|
||||
Returns the current value of the attribute modulo C<$value>.
|
||||
|
||||
=item * B<abs>
|
||||
|
||||
Sets the current value of the attribute to its absolute value.
|
||||
|
||||
=back
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
See L<Moose/BUGS> for details on reporting bugs.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
187
CPAN/Moose/Meta/Attribute/Native/Trait/String.pm
Normal file
187
CPAN/Moose/Meta/Attribute/Native/Trait/String.pm
Normal file
@@ -0,0 +1,187 @@
|
||||
package Moose::Meta::Attribute::Native::Trait::String;
|
||||
our $VERSION = '2.2207';
|
||||
|
||||
use Moose::Role;
|
||||
with 'Moose::Meta::Attribute::Native::Trait';
|
||||
|
||||
sub _helper_type { 'Str' }
|
||||
|
||||
no Moose::Role;
|
||||
|
||||
1;
|
||||
|
||||
# ABSTRACT: Helper trait for Str attributes
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Moose::Meta::Attribute::Native::Trait::String - Helper trait for Str attributes
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
version 2.2207
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
package MyHomePage;
|
||||
use Moose;
|
||||
|
||||
has 'text' => (
|
||||
traits => ['String'],
|
||||
is => 'rw',
|
||||
isa => 'Str',
|
||||
default => q{},
|
||||
handles => {
|
||||
add_text => 'append',
|
||||
replace_text => 'replace',
|
||||
},
|
||||
);
|
||||
|
||||
my $page = MyHomePage->new();
|
||||
$page->add_text("foo"); # same as $page->text($page->text . "foo");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This trait provides native delegation methods for strings.
|
||||
|
||||
=head1 DEFAULT TYPE
|
||||
|
||||
If you don't provide an C<isa> value for your attribute, it will default to
|
||||
C<Str>.
|
||||
|
||||
=head1 PROVIDED METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item * B<inc>
|
||||
|
||||
Increments the value stored in this slot using the magical string autoincrement
|
||||
operator. Note that Perl doesn't provide analogous behavior in C<-->, so
|
||||
C<dec> is not available. This method returns the new value.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<append($string)>
|
||||
|
||||
Appends to the string, like C<.=>, and returns the new value.
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<prepend($string)>
|
||||
|
||||
Prepends to the string and returns the new value.
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<replace($pattern, $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. This method returns the new value.
|
||||
|
||||
This method requires two arguments.
|
||||
|
||||
=item * B<match($pattern)>
|
||||
|
||||
Runs the regex against the string and returns the matching value(s).
|
||||
|
||||
This method requires a single argument.
|
||||
|
||||
=item * B<chop>
|
||||
|
||||
Just like L<perlfunc/chop>. This method returns the chopped character.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<chomp>
|
||||
|
||||
Just like L<perlfunc/chomp>. This method returns the number of characters
|
||||
removed.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<clear>
|
||||
|
||||
Sets the string to the empty string (not the value passed to C<default>).
|
||||
|
||||
This method does not have a defined return value.
|
||||
|
||||
This method does not accept any arguments.
|
||||
|
||||
=item * B<length>
|
||||
|
||||
Just like L<perlfunc/length>, returns the length of the string.
|
||||
|
||||
=item * B<substr>
|
||||
|
||||
This acts just like L<perlfunc/substr>. When called as a writer, it returns
|
||||
the substring that was replaced, just like the Perl builtin.
|
||||
|
||||
This method requires at least one argument, and accepts no more than three.
|
||||
|
||||
=back
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
See L<Moose/BUGS> for details on reporting bugs.
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Stevan Little <stevan@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Dave Rolsky <autarch@urth.org>
|
||||
|
||||
=item *
|
||||
|
||||
Jesse Luehrs <doy@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Shawn M Moore <sartak@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
|
||||
|
||||
=item *
|
||||
|
||||
Karen Etheridge <ether@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Florian Ragwitz <rafl@debian.org>
|
||||
|
||||
=item *
|
||||
|
||||
Hans Dieter Pearcey <hdp@cpan.org>
|
||||
|
||||
=item *
|
||||
|
||||
Chris Prather <chris@prather.org>
|
||||
|
||||
=item *
|
||||
|
||||
Matt S Trout <mstrout@cpan.org>
|
||||
|
||||
=back
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
This software is copyright (c) 2006 by Infinity Interactive, Inc.
|
||||
|
||||
This is free software; you can redistribute it and/or modify it under
|
||||
the same terms as the Perl 5 programming language system itself.
|
||||
|
||||
=cut
|
||||
Reference in New Issue
Block a user