From: Dave Rolsky Date: Fri, 26 Jun 2009 20:52:53 +0000 (-0500) Subject: perltidy all the AttributeHelpers code X-Git-Tag: 0.89_02~109 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=046c8b5ea633c64b5c076a4eb92a95bf892de3b4;p=gitmo%2FMoose.git perltidy all the AttributeHelpers code --- diff --git a/lib/Moose/AttributeHelpers/MethodProvider/Array.pm b/lib/Moose/AttributeHelpers/MethodProvider/Array.pm index 488eae9..a8161ec 100644 --- a/lib/Moose/AttributeHelpers/MethodProvider/Array.pm +++ b/lib/Moose/AttributeHelpers/MethodProvider/Array.pm @@ -8,99 +8,127 @@ our $AUTHORITY = 'cpan:STEVAN'; 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 " . @_; @@ -111,11 +139,11 @@ sub accessor : method { 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 " . @_; @@ -125,72 +153,88 @@ sub accessor : method { } 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 ); }; } diff --git a/lib/Moose/AttributeHelpers/MethodProvider/Bag.pm b/lib/Moose/AttributeHelpers/MethodProvider/Bag.pm index e5f8df9..464eb14 100644 --- a/lib/Moose/AttributeHelpers/MethodProvider/Bag.pm +++ b/lib/Moose/AttributeHelpers/MethodProvider/Bag.pm @@ -8,18 +8,18 @@ our $AUTHORITY = 'cpan:STEVAN'; 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; diff --git a/lib/Moose/AttributeHelpers/MethodProvider/Bool.pm b/lib/Moose/AttributeHelpers/MethodProvider/Bool.pm index 261cbc4..eff7d77 100644 --- a/lib/Moose/AttributeHelpers/MethodProvider/Bool.pm +++ b/lib/Moose/AttributeHelpers/MethodProvider/Bool.pm @@ -7,23 +7,23 @@ $VERSION = eval $VERSION; 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; diff --git a/lib/Moose/AttributeHelpers/MethodProvider/Counter.pm b/lib/Moose/AttributeHelpers/MethodProvider/Counter.pm index e99ebbc..dc8a2ef 100644 --- a/lib/Moose/AttributeHelpers/MethodProvider/Counter.pm +++ b/lib/Moose/AttributeHelpers/MethodProvider/Counter.pm @@ -7,23 +7,29 @@ $VERSION = eval $VERSION; 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; diff --git a/lib/Moose/AttributeHelpers/MethodProvider/Hash.pm b/lib/Moose/AttributeHelpers/MethodProvider/Hash.pm index 1f919ae..b023f2a 100644 --- a/lib/Moose/AttributeHelpers/MethodProvider/Hash.pm +++ b/lib/Moose/AttributeHelpers/MethodProvider/Hash.pm @@ -8,63 +8,79 @@ our $AUTHORITY = 'cpan:STEVAN'; 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 " . @_; @@ -75,11 +91,11 @@ sub accessor : method { 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 " . @_; @@ -89,12 +105,12 @@ sub accessor : method { } 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}{@_}; diff --git a/lib/Moose/AttributeHelpers/MethodProvider/ImmutableHash.pm b/lib/Moose/AttributeHelpers/MethodProvider/ImmutableHash.pm index e31089c..417fae2 100644 --- a/lib/Moose/AttributeHelpers/MethodProvider/ImmutableHash.pm +++ b/lib/Moose/AttributeHelpers/MethodProvider/ImmutableHash.pm @@ -6,65 +6,62 @@ $VERSION = eval $VERSION; 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; diff --git a/lib/Moose/AttributeHelpers/MethodProvider/List.pm b/lib/Moose/AttributeHelpers/MethodProvider/List.pm index 884de75..d90bae3 100644 --- a/lib/Moose/AttributeHelpers/MethodProvider/List.pm +++ b/lib/Moose/AttributeHelpers/MethodProvider/List.pm @@ -6,24 +6,24 @@ $VERSION = eval $VERSION; 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; @@ -31,71 +31,71 @@ sub find : method { } 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]; }; } diff --git a/lib/Moose/AttributeHelpers/MethodProvider/String.pm b/lib/Moose/AttributeHelpers/MethodProvider/String.pm index 1a02cd5..b3a14ab 100644 --- a/lib/Moose/AttributeHelpers/MethodProvider/String.pm +++ b/lib/Moose/AttributeHelpers/MethodProvider/String.pm @@ -7,88 +7,89 @@ $VERSION = eval $VERSION; 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; diff --git a/lib/Moose/AttributeHelpers/Trait/Base.pm b/lib/Moose/AttributeHelpers/Trait/Base.pm index e237372..77dc93d 100644 --- a/lib/Moose/AttributeHelpers/Trait/Base.pm +++ b/lib/Moose/AttributeHelpers/Trait/Base.pm @@ -39,47 +39,52 @@ has 'method_constructors' => ( # 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; }; @@ -95,9 +100,9 @@ sub check_handles_values { 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"; } @@ -105,9 +110,9 @@ sub check_handles_values { 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 ||= []; @@ -124,7 +129,7 @@ around '_make_delegation_method' => sub { $handle_name, sub { my $instance = shift; - return $code->($instance, @$curried_args, @_); + return $code->( $instance, @$curried_args, @_ ); }, ); }; diff --git a/lib/Moose/AttributeHelpers/Trait/Bool.pm b/lib/Moose/AttributeHelpers/Trait/Bool.pm index 9cda87c..707aca6 100644 --- a/lib/Moose/AttributeHelpers/Trait/Bool.pm +++ b/lib/Moose/AttributeHelpers/Trait/Bool.pm @@ -24,10 +24,10 @@ has 'method_provider' => ( ); 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; } }; diff --git a/lib/Moose/AttributeHelpers/Trait/Collection/Bag.pm b/lib/Moose/AttributeHelpers/Trait/Collection/Bag.pm index 3a8fef3..723d716 100644 --- a/lib/Moose/AttributeHelpers/Trait/Collection/Bag.pm +++ b/lib/Moose/AttributeHelpers/Trait/Collection/Bag.pm @@ -23,14 +23,15 @@ subtype 'Bag' => as 'HashRef[Int]'; 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; diff --git a/lib/Moose/AttributeHelpers/Trait/Counter.pm b/lib/Moose/AttributeHelpers/Trait/Counter.pm index 6a3d700..f478ac3 100644 --- a/lib/Moose/AttributeHelpers/Trait/Counter.pm +++ b/lib/Moose/AttributeHelpers/Trait/Counter.pm @@ -20,10 +20,10 @@ has 'method_provider' => ( 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; } @@ -32,15 +32,15 @@ before 'process_options_for_handles' => sub { }; 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); diff --git a/lib/Moose/AttributeHelpers/Trait/Number.pm b/lib/Moose/AttributeHelpers/Trait/Number.pm index 1adb8f7..1119096 100644 --- a/lib/Moose/AttributeHelpers/Trait/Number.pm +++ b/lib/Moose/AttributeHelpers/Trait/Number.pm @@ -22,34 +22,34 @@ has 'method_constructors' => ( 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] ) ) ) }; }, - } + }; } ); diff --git a/lib/Moose/AttributeHelpers/Trait/String.pm b/lib/Moose/AttributeHelpers/Trait/String.pm index e9737e2..912b7ca 100644 --- a/lib/Moose/AttributeHelpers/Trait/String.pm +++ b/lib/Moose/AttributeHelpers/Trait/String.pm @@ -20,10 +20,10 @@ has 'method_provider' => ( 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; } @@ -32,15 +32,15 @@ before 'process_options_for_handles' => sub { }; 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 ); } } };