Add Moose package
All checks were successful
release / release-plugins (push) Successful in 28s

This commit is contained in:
mschuepbach
2024-04-24 13:33:38 +02:00
parent 24101a5c1a
commit d95734d3d0
413 changed files with 47294 additions and 1 deletions

View File

@@ -0,0 +1,244 @@
package Moose::Meta::Attribute::Native::Trait;
our $VERSION = '2.2207';
use Moose::Role;
use Module::Runtime 'require_module';
use Moose::Deprecated;
use Moose::Util 'throw_exception';
use Moose::Util::TypeConstraints;
requires '_helper_type';
before '_process_options' => sub {
my ( $self, $name, $options ) = @_;
$self->_check_helper_type( $options, $name );
};
sub _check_helper_type {
my ( $self, $options, $name ) = @_;
my $type = $self->_helper_type;
$options->{isa} = $type
unless exists $options->{isa};
my $isa;
my $isa_name;
if ( blessed( $options->{isa} )
&& $options->{isa}->can('does')
&& $options->{isa}->does('Specio::Constraint::Role::Interface') ) {
$isa = $options->{isa};
require Specio::Library::Builtins;
return if $isa->is_a_type_of( Specio::Library::Builtins::t($type) );
$isa_name = $isa->name() || $isa->description();
}
else {
$isa = Moose::Util::TypeConstraints::find_or_create_type_constraint(
$options->{isa} );
return if $isa->is_a_type_of($type);
$isa_name = $isa->name();
}
throw_exception( WrongTypeConstraintGiven => required_type => $type,
given_type => $isa_name,
attribute_name => $name,
params => $options
);
}
before 'install_accessors' => sub { (shift)->_check_handles_values };
sub _check_handles_values {
my $self = shift;
my %handles = $self->_canonicalize_handles;
for my $original_method ( values %handles ) {
my $name = $original_method->[0];
my $accessor_class = $self->_native_accessor_class_for($name);
( $accessor_class && $accessor_class->can('new') )
|| confess
"$name is an unsupported method type - $accessor_class";
}
}
around '_canonicalize_handles' => sub {
shift;
my $self = shift;
my $handles = $self->handles;
return unless $handles;
unless ( 'HASH' eq ref $handles ) {
throw_exception( HandlesMustBeAHashRef => instance => $self,
given_handles => $handles
);
}
return
map { $_ => $self->_canonicalize_handles_value( $handles->{$_} ) }
keys %$handles;
};
sub _canonicalize_handles_value {
my $self = shift;
my $value = shift;
if ( ref $value && 'ARRAY' ne ref $value ) {
throw_exception( InvalidHandleValue => instance => $self,
handle_value => $value
);
}
return ref $value ? $value : [$value];
}
around '_make_delegation_method' => sub {
my $next = shift;
my ( $self, $handle_name, $method_to_call ) = @_;
my ( $name, @curried_args ) = @$method_to_call;
my $accessor_class = $self->_native_accessor_class_for($name);
die "Cannot find an accessor class for $name"
unless $accessor_class && $accessor_class->can('new');
return $accessor_class->new(
name => $handle_name,
package_name => $self->associated_class->name,
delegate_to_method => $name,
attribute => $self,
is_inline => 1,
curried_arguments => \@curried_args,
root_types => [ $self->_root_types ],
);
};
sub _root_types {
return $_[0]->_helper_type;
}
sub _native_accessor_class_for {
my ( $self, $suffix ) = @_;
my $role
= 'Moose::Meta::Method::Accessor::Native::'
. $self->_native_type . '::'
. $suffix;
require_module($role);
return Moose::Meta::Class->create_anon_class(
superclasses =>
[ $self->accessor_metaclass, $self->delegation_metaclass ],
roles => [$role],
cache => 1,
)->name;
}
sub _build_native_type {
my $self = shift;
for my $role_name ( map { $_->name } $self->meta->calculate_all_roles ) {
return $1 if $role_name =~ /::Native::Trait::(\w+)$/;
}
throw_exception( CannotCalculateNativeType => instance => $self );
}
has '_native_type' => (
is => 'ro',
isa => 'Str',
lazy => 1,
builder => '_build_native_type',
);
no Moose::Role;
no Moose::Util::TypeConstraints;
1;
# ABSTRACT: Shared role for native delegation traits
__END__
=pod
=encoding UTF-8
=head1 NAME
Moose::Meta::Attribute::Native::Trait - Shared role for native delegation traits
=head1 VERSION
version 2.2207
=head1 BUGS
See L<Moose/BUGS> for details on reporting bugs.
=head1 SEE ALSO
Documentation for Moose native traits can be found in
L<Moose::Meta::Attribute::Native>.
=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

View 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

View 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

View 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

View 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

View 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

View 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

View 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