with 'Moose::AttributeHelpers::MethodProvider::List';
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;
+ 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 '$container_type_constraint'"
- foreach @_;
- CORE::push @{$reader->($instance)} => @_;
+ || confess "Value "
+ . ( $_ || 'undef' )
+ . " did not pass container type constraint '$container_type_constraint'"
+ foreach @_;
+ CORE::push @{ $reader->($instance) } => @_;
};
}
else {
return sub {
my $instance = CORE::shift;
- CORE::push @{$reader->($instance)} => @_;
+ CORE::push @{ $reader->($instance) } => @_;
};
}
}
sub pop : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- CORE::pop @{$reader->($_[0])}
+ 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;
+ 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 '$container_type_constraint'"
- foreach @_;
- CORE::unshift @{$reader->($instance)} => @_;
+ || confess "Value "
+ . ( $_ || 'undef' )
+ . " did not pass container type constraint '$container_type_constraint'"
+ foreach @_;
+ CORE::unshift @{ $reader->($instance) } => @_;
};
}
else {
return sub {
my $instance = CORE::shift;
- CORE::unshift @{$reader->($instance)} => @_;
+ CORE::unshift @{ $reader->($instance) } => @_;
};
}
}
sub shift : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- CORE::shift @{$reader->($_[0])}
+ CORE::shift @{ $reader->( $_[0] ) };
};
}
sub get : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- $reader->($_[0])->[$_[1]]
+ $reader->( $_[0] )->[ $_[1] ];
};
}
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;
+ 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 '$container_type_constraint'";
- $reader->($_[0])->[$_[1]] = $_[2]
+ ( $container_type_constraint->check( $_[2] ) )
+ || confess "Value "
+ . ( $_[2] || 'undef' )
+ . " did not pass container type constraint '$container_type_constraint'";
+ $reader->( $_[0] )->[ $_[1] ] = $_[2];
};
}
else {
return sub {
- $reader->($_[0])->[$_[1]] = $_[2]
+ $reader->( $_[0] )->[ $_[1] ] = $_[2];
};
}
}
sub accessor : 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;
+ 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 = shift;
- if (@_ == 1) { # reader
- return $reader->($self)->[$_[0]];
+ if ( @_ == 1 ) { # reader
+ return $reader->($self)->[ $_[0] ];
}
- elsif (@_ == 2) { # writer
- ($container_type_constraint->check($_[1]))
- || confess "Value " . ($_[1]||'undef') . " did not pass container type constraint '$container_type_constraint'";
- $reader->($self)->[$_[0]] = $_[1];
+ elsif ( @_ == 2 ) { # writer
+ ( $container_type_constraint->check( $_[1] ) )
+ || confess "Value "
+ . ( $_[1] || 'undef' )
+ . " did not pass container type constraint '$container_type_constraint'";
+ $reader->($self)->[ $_[0] ] = $_[1];
}
else {
confess "One or two arguments expected, not " . @_;
return sub {
my $self = shift;
- if (@_ == 1) { # reader
- return $reader->($self)->[$_[0]];
+ if ( @_ == 1 ) { # reader
+ return $reader->($self)->[ $_[0] ];
}
- elsif (@_ == 2) { # writer
- $reader->($self)->[$_[0]] = $_[1];
+ elsif ( @_ == 2 ) { # writer
+ $reader->($self)->[ $_[0] ] = $_[1];
}
else {
confess "One or two arguments expected, not " . @_;
}
sub clear : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- @{$reader->($_[0])} = ()
+ @{ $reader->( $_[0] ) } = ();
};
}
sub delete : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- CORE::splice @{$reader->($_[0])}, $_[1], 1;
- }
+ CORE::splice @{ $reader->( $_[0] ) }, $_[1], 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;
+ 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 '$container_type_constraint'";
- CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
+ ( $container_type_constraint->check( $_[2] ) )
+ || confess "Value "
+ . ( $_[2] || 'undef' )
+ . " did not pass container type constraint '$container_type_constraint'";
+ CORE::splice @{ $reader->( $_[0] ) }, $_[1], 0, $_[2];
};
}
else {
return sub {
- CORE::splice @{$reader->($_[0])}, $_[1], 0, $_[2];
+ CORE::splice @{ $reader->( $_[0] ) }, $_[1], 0, $_[2];
};
}
}
sub splice : 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;
+ 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, $i, $j, @elems ) = @_;
- ($container_type_constraint->check($_))
- || confess "Value " . (defined($_) ? $_ : 'undef') . " did not pass container type constraint '$container_type_constraint'" for @elems;
- CORE::splice @{$reader->($self)}, $i, $j, @elems;
+ ( $container_type_constraint->check($_) )
+ || confess "Value "
+ . ( defined($_) ? $_ : 'undef' )
+ . " did not pass container type constraint '$container_type_constraint'"
+ for @elems;
+ CORE::splice @{ $reader->($self) }, $i, $j, @elems;
};
}
else {
return sub {
my ( $self, $i, $j, @elems ) = @_;
- CORE::splice @{$reader->($self)}, $i, $j, @elems;
+ CORE::splice @{ $reader->($self) }, $i, $j, @elems;
};
}
}
sub sort_in_place : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my ($instance, $predicate) = @_;
+ my ( $instance, $predicate ) = @_;
die "Argument must be a code reference"
if $predicate && ref $predicate ne 'CODE';
my @sorted;
if ($predicate) {
- @sorted = CORE::sort { $predicate->($a, $b) } @{$reader->($instance)};
+ @sorted = CORE::sort { $predicate->( $a, $b ) }
+ @{ $reader->($instance) };
}
else {
- @sorted = CORE::sort @{$reader->($instance)};
+ @sorted = CORE::sort @{ $reader->($instance) };
}
- $writer->($instance, \@sorted);
+ $writer->( $instance, \@sorted );
};
}
with 'Moose::AttributeHelpers::MethodProvider::ImmutableHash';
sub add : method {
- my ($attr, $reader, $writer) = @_;
- return sub { $reader->($_[0])->{$_[1]}++ };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $reader->( $_[0] )->{ $_[1] }++ };
}
sub delete : method {
- my ($attr, $reader, $writer) = @_;
- return sub { CORE::delete $reader->($_[0])->{$_[1]} };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { CORE::delete $reader->( $_[0] )->{ $_[1] } };
}
sub reset : method {
- my ($attr, $reader, $writer) = @_;
- return sub { $reader->($_[0])->{$_[1]} = 0 };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $reader->( $_[0] )->{ $_[1] } = 0 };
}
1;
our $AUTHORITY = 'cpan:STEVAN';
sub set : method {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], 1) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], 1 ) };
}
sub unset : method {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], 0) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], 0 ) };
}
sub toggle : method {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], !$reader->($_[0])) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], !$reader->( $_[0] ) ) };
}
sub not : method {
- my ($attr, $reader, $writer) = @_;
- return sub { !$reader->($_[0]) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { !$reader->( $_[0] ) };
}
1;
our $AUTHORITY = 'cpan:STEVAN';
sub reset : method {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $attr->default($_[0])) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], $attr->default( $_[0] ) ) };
}
sub set : method {
- my ($attr, $reader, $writer, $value) = @_;
- return sub { $writer->($_[0], $_[1]) };
+ my ( $attr, $reader, $writer, $value ) = @_;
+ return sub { $writer->( $_[0], $_[1] ) };
}
sub inc {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) + (defined($_[1]) ? $_[1] : 1) ) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub {
+ $writer->( $_[0],
+ $reader->( $_[0] ) + ( defined( $_[1] ) ? $_[1] : 1 ) );
+ };
}
sub dec {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) - (defined($_[1]) ? $_[1] : 1) ) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub {
+ $writer->( $_[0],
+ $reader->( $_[0] ) - ( defined( $_[1] ) ? $_[1] : 1 ) );
+ };
}
1;
with 'Moose::AttributeHelpers::MethodProvider::ImmutableHash';
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;
+ 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 ) {
+ while (@kvp) {
my ( $key, $value ) = ( shift(@kvp), shift(@kvp) );
- ($container_type_constraint->check($value))
- || confess "Value " . ($value||'undef') . " did not pass container type constraint '$container_type_constraint'";
- push @keys, $key;
+ ( $container_type_constraint->check($value) )
+ || confess "Value "
+ . ( $value || 'undef' )
+ . " did not pass container type constraint '$container_type_constraint'";
+ push @keys, $key;
push @values, $value;
}
if ( @values > 1 ) {
@{ $reader->($self) }{@keys} = @values;
- } else {
- $reader->($self)->{$keys[0]} = $values[0];
+ }
+ else {
+ $reader->($self)->{ $keys[0] } = $values[0];
}
};
}
else {
return sub {
if ( @_ == 3 ) {
- $reader->($_[0])->{$_[1]} = $_[2]
- } else {
+ $reader->( $_[0] )->{ $_[1] } = $_[2];
+ }
+ else {
my ( $self, @kvp ) = @_;
my ( @keys, @values );
- while ( @kvp ) {
- push @keys, shift @kvp;
+ while (@kvp) {
+ push @keys, shift @kvp;
push @values, shift @kvp;
}
- @{ $reader->($_[0]) }{@keys} = @values;
+ @{ $reader->( $_[0] ) }{@keys} = @values;
}
};
}
}
sub accessor : 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;
+ 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 = shift;
- if (@_ == 1) { # reader
- return $reader->($self)->{$_[0]};
+ if ( @_ == 1 ) { # reader
+ return $reader->($self)->{ $_[0] };
}
- elsif (@_ == 2) { # writer
- ($container_type_constraint->check($_[1]))
- || confess "Value " . ($_[1]||'undef') . " did not pass container type constraint '$container_type_constraint'";
- $reader->($self)->{$_[0]} = $_[1];
+ elsif ( @_ == 2 ) { # writer
+ ( $container_type_constraint->check( $_[1] ) )
+ || confess "Value "
+ . ( $_[1] || 'undef' )
+ . " did not pass container type constraint '$container_type_constraint'";
+ $reader->($self)->{ $_[0] } = $_[1];
}
else {
confess "One or two arguments expected, not " . @_;
return sub {
my $self = shift;
- if (@_ == 1) { # reader
- return $reader->($self)->{$_[0]};
+ if ( @_ == 1 ) { # reader
+ return $reader->($self)->{ $_[0] };
}
- elsif (@_ == 2) { # writer
- $reader->($self)->{$_[0]} = $_[1];
+ elsif ( @_ == 2 ) { # writer
+ $reader->($self)->{ $_[0] } = $_[1];
}
else {
confess "One or two arguments expected, not " . @_;
}
sub clear : method {
- my ($attr, $reader, $writer) = @_;
- return sub { %{$reader->($_[0])} = () };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { %{ $reader->( $_[0] ) } = () };
}
sub delete : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
my $hashref = $reader->(shift);
CORE::delete @{$hashref}{@_};
our $AUTHORITY = 'cpan:STEVAN';
sub exists : method {
- my ($attr, $reader, $writer) = @_;
- return sub { CORE::exists $reader->($_[0])->{$_[1]} ? 1 : 0 };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { CORE::exists $reader->( $_[0] )->{ $_[1] } ? 1 : 0 };
}
sub defined : method {
- my ($attr, $reader, $writer) = @_;
- return sub { CORE::defined $reader->($_[0])->{$_[1]} ? 1 : 0 };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { CORE::defined $reader->( $_[0] )->{ $_[1] } ? 1 : 0 };
}
sub get : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
if ( @_ == 2 ) {
- $reader->($_[0])->{$_[1]}
- } else {
+ $reader->( $_[0] )->{ $_[1] };
+ }
+ else {
my ( $self, @keys ) = @_;
- @{ $reader->($self) }{@keys}
+ @{ $reader->($self) }{@keys};
}
};
}
sub keys : method {
- my ($attr, $reader, $writer) = @_;
- return sub { CORE::keys %{$reader->($_[0])} };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { CORE::keys %{ $reader->( $_[0] ) } };
}
sub values : method {
- my ($attr, $reader, $writer) = @_;
- return sub { CORE::values %{$reader->($_[0])} };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { CORE::values %{ $reader->( $_[0] ) } };
}
sub kv : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my $h = $reader->($_[0]);
- map {
- [ $_, $h->{$_} ]
- } CORE::keys %{$h}
+ my $h = $reader->( $_[0] );
+ map { [ $_, $h->{$_} ] } CORE::keys %{$h};
};
}
sub elements : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my $h = $reader->($_[0]);
- map {
- $_, $h->{$_}
- } CORE::keys %{$h}
+ my $h = $reader->( $_[0] );
+ map { $_, $h->{$_} } CORE::keys %{$h};
};
}
sub count : method {
- my ($attr, $reader, $writer) = @_;
- return sub { scalar CORE::keys %{$reader->($_[0])} };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { scalar CORE::keys %{ $reader->( $_[0] ) } };
}
sub empty : method {
- my ($attr, $reader, $writer) = @_;
- return sub { scalar CORE::keys %{$reader->($_[0])} ? 1 : 0 };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { scalar CORE::keys %{ $reader->( $_[0] ) } ? 1 : 0 };
}
1;
our $AUTHORITY = 'cpan:STEVAN';
sub count : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- scalar @{$reader->($_[0])}
+ scalar @{ $reader->( $_[0] ) };
};
}
sub empty : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- scalar @{$reader->($_[0])} ? 1 : 0
+ scalar @{ $reader->( $_[0] ) } ? 1 : 0;
};
}
sub find : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my ($instance, $predicate) = @_;
- foreach my $val (@{$reader->($instance)}) {
+ my ( $instance, $predicate ) = @_;
+ foreach my $val ( @{ $reader->($instance) } ) {
return $val if $predicate->($val);
}
return;
}
sub map : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my ($instance, $f) = @_;
- CORE::map { $f->($_) } @{$reader->($instance)}
+ my ( $instance, $f ) = @_;
+ CORE::map { $f->($_) } @{ $reader->($instance) };
};
}
sub sort : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my ($instance, $predicate) = @_;
+ my ( $instance, $predicate ) = @_;
die "Argument must be a code reference"
if $predicate && ref $predicate ne 'CODE';
if ($predicate) {
- CORE::sort { $predicate->($a, $b) } @{$reader->($instance)};
+ CORE::sort { $predicate->( $a, $b ) } @{ $reader->($instance) };
}
else {
- CORE::sort @{$reader->($instance)};
+ CORE::sort @{ $reader->($instance) };
}
};
}
sub grep : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my ($instance, $predicate) = @_;
- CORE::grep { $predicate->($_) } @{$reader->($instance)}
+ my ( $instance, $predicate ) = @_;
+ CORE::grep { $predicate->($_) } @{ $reader->($instance) };
};
}
sub elements : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
my ($instance) = @_;
- @{$reader->($instance)}
+ @{ $reader->($instance) };
};
}
sub join : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my ($instance, $separator) = @_;
- join $separator, @{$reader->($instance)}
+ my ( $instance, $separator ) = @_;
+ join $separator, @{ $reader->($instance) };
};
}
sub get : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- $reader->($_[0])->[$_[1]]
+ $reader->( $_[0] )->[ $_[1] ];
};
}
sub first : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- $reader->($_[0])->[0]
+ $reader->( $_[0] )->[0];
};
}
sub last : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- $reader->($_[0])->[-1]
+ $reader->( $_[0] )->[-1];
};
}
our $AUTHORITY = 'cpan:STEVAN';
sub append : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
- return sub { $writer->( $_[0], $reader->($_[0]) . $_[1] ) };
+ return sub { $writer->( $_[0], $reader->( $_[0] ) . $_[1] ) };
}
sub prepend : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
- return sub { $writer->( $_[0], $_[1] . $reader->($_[0]) ) };
+ return sub { $writer->( $_[0], $_[1] . $reader->( $_[0] ) ) };
}
sub replace : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
my ( $self, $regex, $replacement ) = @_;
- my $v = $reader->($_[0]);
+ my $v = $reader->( $_[0] );
- if ( (ref($replacement)||'') eq 'CODE' ) {
+ if ( ( ref($replacement) || '' ) eq 'CODE' ) {
$v =~ s/$regex/$replacement->()/e;
- } else {
+ }
+ else {
$v =~ s/$regex/$replacement/;
}
- $writer->( $_[0], $v);
+ $writer->( $_[0], $v );
};
}
sub match : method {
- my ($attr, $reader, $writer) = @_;
- return sub { $reader->($_[0]) =~ $_[1] };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $reader->( $_[0] ) =~ $_[1] };
}
sub chop : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my $v = $reader->($_[0]);
+ my $v = $reader->( $_[0] );
CORE::chop($v);
- $writer->( $_[0], $v);
+ $writer->( $_[0], $v );
};
}
sub chomp : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my $v = $reader->($_[0]);
+ my $v = $reader->( $_[0] );
chomp($v);
- $writer->( $_[0], $v);
+ $writer->( $_[0], $v );
};
}
sub inc : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
- my $v = $reader->($_[0]);
+ my $v = $reader->( $_[0] );
$v++;
- $writer->( $_[0], $v);
+ $writer->( $_[0], $v );
};
}
sub clear : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub { $writer->( $_[0], '' ) }
}
sub substr : method {
- my ($attr, $reader, $writer) = @_;
+ my ( $attr, $reader, $writer ) = @_;
return sub {
my $self = shift;
- my $v = $reader->($self);
+ my $v = $reader->($self);
my $offset = defined $_[0] ? shift : 0;
my $length = defined $_[0] ? shift : CORE::length($v);
my $replacement = defined $_[0] ? shift : undef;
my $ret;
- if (defined $replacement) {
- $ret = CORE::substr($v, $offset, $length, $replacement);
- $writer->($self, $v);
+ if ( defined $replacement ) {
+ $ret = CORE::substr( $v, $offset, $length, $replacement );
+ $writer->( $self, $v );
}
else {
- $ret = CORE::substr($v, $offset, $length);
+ $ret = CORE::substr( $v, $offset, $length );
}
return $ret;
# extend the parents stuff to make sure
# certain bits are now required ...
-has '+default' => (required => 1);
-has '+type_constraint' => (required => 1);
+has '+default' => ( required => 1 );
+has '+type_constraint' => ( required => 1 );
## Methods called prior to instantiation
sub process_options_for_handles {
- my ($self, $options) = @_;
+ my ( $self, $options ) = @_;
- if (my $type = $self->helper_type) {
- (exists $options->{isa})
+ if ( my $type = $self->helper_type ) {
+ ( exists $options->{isa} )
|| confess "You must define a type with the $type metaclass";
my $isa = $options->{isa};
- unless (blessed($isa) && $isa->isa('Moose::Meta::TypeConstraint')) {
- $isa = Moose::Util::TypeConstraints::find_or_create_type_constraint($isa);
+ unless ( blessed($isa) && $isa->isa('Moose::Meta::TypeConstraint') ) {
+ $isa
+ = Moose::Util::TypeConstraints::find_or_create_type_constraint(
+ $isa);
}
- ($isa->is_a_type_of($type))
- || confess "The type constraint for a $type ($options->{isa}) must be a subtype of $type";
+ ( $isa->is_a_type_of($type) )
+ || confess
+ "The type constraint for a $type ($options->{isa}) must be a subtype of $type";
}
}
before '_process_options' => sub {
- my ($self, $name, $options) = @_;
- $self->process_options_for_handles($options, $name);
+ my ( $self, $name, $options ) = @_;
+ $self->process_options_for_handles( $options, $name );
};
around '_canonicalize_handles' => sub {
my $next = shift;
my $self = shift;
my $handles = $self->handles;
+
return unless $handles;
- unless ('HASH' eq ref $handles) {
+
+ unless ( 'HASH' eq ref $handles ) {
$self->throw_error(
- "The 'handles' option must be a HASH reference, not $handles"
- );
+ "The 'handles' option must be a HASH reference, not $handles" );
}
+
return map {
my $to = $handles->{$_};
- $to = [ $to ] unless ref $to;
+ $to = [$to] unless ref $to;
$_ => $to
} keys %$handles;
};
my %handles = $self->_canonicalize_handles;
- for my $original_method (values %handles) {
+ for my $original_method ( values %handles ) {
my $name = $original_method->[0];
- (exists $method_constructors->{$name})
+ ( exists $method_constructors->{$name} )
|| confess "$name is an unsupported method type";
}
around '_make_delegation_method' => sub {
my $next = shift;
- my ($self, $handle_name, $method_to_call) = @_;
+ my ( $self, $handle_name, $method_to_call ) = @_;
- my ($name, $curried_args) = @$method_to_call;
+ my ( $name, $curried_args ) = @$method_to_call;
$curried_args ||= [];
$handle_name,
sub {
my $instance = shift;
- return $code->($instance, @$curried_args, @_);
+ return $code->( $instance, @$curried_args, @_ );
},
);
};
);
before 'process_options_for_handles' => sub {
- my ($self, $options, $name) = @_;
+ my ( $self, $options, $name ) = @_;
# Set some default attribute options here unless already defined
- if ((my $type = $self->helper_type) && !exists $options->{isa}){
+ if ( ( my $type = $self->helper_type ) && !exists $options->{isa} ) {
$options->{isa} = $type;
}
};
sub helper_type { 'Bag' }
before 'process_options_for_handles' => sub {
- my ($self, $options, $name) = @_;
+ my ( $self, $options, $name ) = @_;
# Set some default attribute options here unless already defined
- if ((my $type = $self->helper_type) && !exists $options->{isa}){
+ if ( ( my $type = $self->helper_type ) && !exists $options->{isa} ) {
$options->{isa} = $type;
}
- $options->{default} = sub { +{} } unless exists $options->{default};
+ $options->{default} = sub { +{} }
+ unless exists $options->{default};
};
no Moose::Role;
sub helper_type { 'Num' }
before 'process_options_for_handles' => sub {
- my ($self, $options, $name) = @_;
+ my ( $self, $options, $name ) = @_;
# Set some default attribute options here unless already defined
- if ((my $type = $self->helper_type) && !exists $options->{isa}){
+ if ( ( my $type = $self->helper_type ) && !exists $options->{isa} ) {
$options->{isa} = $type;
}
};
after 'check_handles_values' => sub {
- my $self = shift;
+ my $self = shift;
my $handles = $self->handles;
- unless (scalar keys %$handles) {
+ unless ( scalar keys %$handles ) {
my $method_constructors = $self->method_constructors;
my $attr_name = $self->name;
- foreach my $method (keys %$method_constructors) {
- $handles->{$method . '_' . $attr_name} = $method;
+ foreach my $method ( keys %$method_constructors ) {
+ $handles->{ $method . '_' . $attr_name } = $method;
}
$self->_set_handles($handles);
default => sub {
return +{
set => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $_[1]) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], $_[1] ) };
},
add => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) + $_[1]) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], $reader->( $_[0] ) + $_[1] ) };
},
sub => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) - $_[1]) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], $reader->( $_[0] ) - $_[1] ) };
},
mul => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) * $_[1]) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], $reader->( $_[0] ) * $_[1] ) };
},
div => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) / $_[1]) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], $reader->( $_[0] ) / $_[1] ) };
},
mod => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], $reader->($_[0]) % $_[1]) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], $reader->( $_[0] ) % $_[1] ) };
},
abs => sub {
- my ($attr, $reader, $writer) = @_;
- return sub { $writer->($_[0], abs($reader->($_[0])) ) };
+ my ( $attr, $reader, $writer ) = @_;
+ return sub { $writer->( $_[0], abs( $reader->( $_[0] ) ) ) };
},
- }
+ };
}
);
sub helper_type { 'Str' }
before 'process_options_for_handles' => sub {
- my ($self, $options, $name) = @_;
+ my ( $self, $options, $name ) = @_;
# Set some default attribute options here unless already defined
- if ((my $type = $self->helper_type) && !exists $options->{isa}){
+ if ( ( my $type = $self->helper_type ) && !exists $options->{isa} ) {
$options->{isa} = $type;
}
};
after 'check_handles_values' => sub {
- my $self = shift;
+ my $self = shift;
my $handles = $self->handles;
- unless (scalar keys %$handles) {
+ unless ( scalar keys %$handles ) {
my $method_constructors = $self->method_constructors;
my $attr_name = $self->name;
- foreach my $method (keys %$method_constructors) {
- $handles->{$method} = ($method . '_' . $attr_name);
+ foreach my $method ( keys %$method_constructors ) {
+ $handles->{$method} = ( $method . '_' . $attr_name );
}
}
};