From: Dave Rolsky Date: Sun, 4 Apr 2010 02:09:39 +0000 (-0500) Subject: run all code through perltidy X-Git-Tag: v0.09~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-StrictConstructor.git;a=commitdiff_plain;h=5a0d49213abe7095b652c725efaad35cff6e24b9 run all code through perltidy --- diff --git a/Build.PL b/Build.PL index 7e6ecbd..16ed57a 100644 --- a/Build.PL +++ b/Build.PL @@ -5,15 +5,16 @@ require 5.008; use Module::Build; -my $builder = Module::Build->new - ( module_name => 'MooseX::StrictConstructor', - license => 'perl', - requires => { 'Moose' => '0.74', - 'Test::More' => '0', - }, - create_makefile_pl => 'passthrough', - create_readme => 1, - sign => 1, - ); +my $builder = Module::Build->new( + module_name => 'MooseX::StrictConstructor', + license => 'perl', + requires => { + 'Moose' => '0.74', + 'Test::More' => '0', + }, + create_makefile_pl => 'passthrough', + create_readme => 1, + sign => 1, +); $builder->create_build_script(); diff --git a/lib/MooseX/StrictConstructor.pm b/lib/MooseX/StrictConstructor.pm index 54a1001..ce01b34 100644 --- a/lib/MooseX/StrictConstructor.pm +++ b/lib/MooseX/StrictConstructor.pm @@ -12,11 +12,9 @@ use Moose::Util::MetaRole; use MooseX::StrictConstructor::Role::Object; use MooseX::StrictConstructor::Role::Meta::Method::Constructor; - Moose::Exporter->setup_import_methods(); -sub init_meta -{ +sub init_meta { shift; my %p = @_; @@ -24,17 +22,17 @@ sub init_meta my $caller = $p{for_class}; - Moose::Util::MetaRole::apply_metaclass_roles - ( for_class => $caller, - constructor_class_roles => - ['MooseX::StrictConstructor::Role::Meta::Method::Constructor'], - ); - - Moose::Util::MetaRole::apply_base_class_roles - ( for_class => $caller, - roles => - [ 'MooseX::StrictConstructor::Role::Object' ], - ); + Moose::Util::MetaRole::apply_metaclass_roles( + for_class => $caller, + constructor_class_roles => + ['MooseX::StrictConstructor::Role::Meta::Method::Constructor'], + ); + + Moose::Util::MetaRole::apply_base_class_roles( + for_class => $caller, + roles => + ['MooseX::StrictConstructor::Role::Object'], + ); return $caller->meta(); } diff --git a/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm b/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm index 5c0a8a4..fa3e7a6 100644 --- a/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm +++ b/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm @@ -7,20 +7,18 @@ use Carp (); use Moose::Role; -around '_generate_BUILDALL' => sub -{ +around '_generate_BUILDALL' => sub { my $orig = shift; my $self = shift; my $source = $self->$orig(); $source .= ";\n" if $source; - my @attrs = - ( map { "$_ => 1," } - grep { defined } - map { $_->init_arg() } - @{ $self->_attributes() } - ); + my @attrs = ( + map {"$_ => 1,"} + grep {defined} + map { $_->init_arg() } @{ $self->_attributes() } + ); $source .= <<"EOF"; my \%attrs = (@attrs); diff --git a/lib/MooseX/StrictConstructor/Role/Object.pm b/lib/MooseX/StrictConstructor/Role/Object.pm index 9f29e60..2e1d871 100644 --- a/lib/MooseX/StrictConstructor/Role/Object.pm +++ b/lib/MooseX/StrictConstructor/Role/Object.pm @@ -5,24 +5,21 @@ use warnings; use Moose::Role; - -after 'BUILDALL' => sub -{ +after 'BUILDALL' => sub { my $self = shift; my $params = shift; - my %attrs = - ( map { $_ => 1 } - grep { defined } - map { $_->init_arg() } - $self->meta()->get_all_attributes() - ); + my %attrs = ( + map { $_ => 1 } + grep {defined} + map { $_->init_arg() } $self->meta()->get_all_attributes() + ); - my @bad = sort grep { ! $attrs{$_} } keys %{ $params }; + my @bad = sort grep { !$attrs{$_} } keys %{$params}; - if (@bad) - { - confess "Found unknown attribute(s) init_arg passed to the constructor: @bad"; + if (@bad) { + confess + "Found unknown attribute(s) init_arg passed to the constructor: @bad"; } return; diff --git a/t/basic.t b/t/basic.t index 24f62ce..57ab8ad 100644 --- a/t/basic.t +++ b/t/basic.t @@ -3,8 +3,8 @@ use warnings; use Test::More tests => 15; - { + package Standard; use Moose; @@ -13,6 +13,7 @@ use Test::More tests => 15; } { + package Stricter; use Moose; @@ -22,6 +23,7 @@ use Test::More tests => 15; } { + package Subclass; use Moose; @@ -33,6 +35,7 @@ use Test::More tests => 15; } { + package Tricky; use Moose; @@ -40,8 +43,7 @@ use Test::More tests => 15; has 'thing' => ( is => 'rw' ); - sub BUILD - { + sub BUILD { my $self = shift; my $params = shift; @@ -50,6 +52,7 @@ use Test::More tests => 15; } { + package InitArg; use Moose; @@ -60,6 +63,7 @@ use Test::More tests => 15; } { + package ImmutableInitArg; use Moose; @@ -73,6 +77,7 @@ use Test::More tests => 15; } { + package Immutable; use Moose; @@ -85,6 +90,7 @@ use Test::More tests => 15; } { + package ImmutableTricky; use Moose; @@ -92,8 +98,7 @@ use Test::More tests => 15; has 'thing' => ( is => 'rw' ); - sub BUILD - { + sub BUILD { my $self = shift; my $params = shift; @@ -104,57 +109,78 @@ use Test::More tests => 15; __PACKAGE__->meta()->make_immutable(); } - eval { Standard->new( thing => 1, bad => 99 ) }; is( $@, '', 'standard Moose class ignores unknown params' ); eval { Stricter->new( thing => 1, bad => 99 ) }; -like( $@, qr/unknown attribute.+: bad/, 'strict constructor blows up on unknown params' ); +like( $@, qr/unknown attribute.+: bad/, + 'strict constructor blows up on unknown params' ); eval { Subclass->new( thing => 1, size => 'large' ) }; is( $@, '', 'subclass constructor handles known attributes correctly' ); eval { Tricky->new( thing => 1, spy => 99 ) }; -is( $@, '', 'can work around strict constructor by deleting params in BUILD()' ); +is( $@, '', + 'can work around strict constructor by deleting params in BUILD()' ); eval { Tricky->new( thing => 1, agent => 99 ) }; -like( $@, qr/unknown attribute.+: agent/, 'Tricky still blows up on unknown params other than spy' ); +like( $@, qr/unknown attribute.+: agent/, + 'Tricky still blows up on unknown params other than spy' ); eval { Subclass->new( thing => 1, bad => 99 ) }; -like( $@, qr/unknown attribute.+: bad/, 'subclass constructor blows up on unknown params' ); +like( $@, qr/unknown attribute.+: bad/, + 'subclass constructor blows up on unknown params' ); eval { InitArg->new( thing => 1 ) }; -like( $@, qr/unknown attribute.+: thing/, - 'InitArg blows up with attribute name' ); +like( + $@, qr/unknown attribute.+: thing/, + 'InitArg blows up with attribute name' +); eval { InitArg->new( size => 1 ) }; -like( $@, qr/unknown attribute.+: size/, - 'InitArg blows up when given attribute with undef init_arg' ); +like( + $@, qr/unknown attribute.+: size/, + 'InitArg blows up when given attribute with undef init_arg' +); eval { InitArg->new( other => 1 ) }; -is( $@, '', - 'InitArg works when given proper init_arg' ); +is( + $@, '', + 'InitArg works when given proper init_arg' +); eval { ImmutableInitArg->new( thing => 1 ) }; -like( $@, qr/unknown attribute.+: thing/, - 'ImmutableInitArg blows up with attribute name' ); +like( + $@, qr/unknown attribute.+: thing/, + 'ImmutableInitArg blows up with attribute name' +); eval { ImmutableInitArg->new( size => 1 ) }; -like( $@, qr/unknown attribute.+: size/, - 'ImmutableInitArg blows up when given attribute with undef init_arg' ); +like( + $@, qr/unknown attribute.+: size/, + 'ImmutableInitArg blows up when given attribute with undef init_arg' +); eval { ImmutableInitArg->new( other => 1 ) }; -is( $@, '', - 'ImmutableInitArg works when given proper init_arg' ); +is( + $@, '', + 'ImmutableInitArg works when given proper init_arg' +); eval { Immutable->new( thing => 1, bad => 99 ) }; -like( $@, qr/unknown attribute.+: bad/, - 'strict constructor in immutable class blows up on unknown params' ); +like( + $@, qr/unknown attribute.+: bad/, + 'strict constructor in immutable class blows up on unknown params' +); eval { ImmutableTricky->new( thing => 1, spy => 99 ) }; -is( $@, '', - 'immutable class can work around strict constructor by deleting params in BUILD()' ); +is( + $@, '', + 'immutable class can work around strict constructor by deleting params in BUILD()' +); eval { ImmutableTricky->new( thing => 1, agent => 99 ) }; -like( $@, qr/unknown attribute.+: agent/, - 'ImmutableTricky still blows up on unknown params other than spy' ); +like( + $@, qr/unknown attribute.+: agent/, + 'ImmutableTricky still blows up on unknown params other than spy' +); diff --git a/t/pod-coverage.t b/t/pod-coverage.t index 6f96ad1..af03b37 100644 --- a/t/pod-coverage.t +++ b/t/pod-coverage.t @@ -3,7 +3,6 @@ use warnings; use Test::More; - plan skip_all => 'This test is only run for the module author' unless -d '.svn' || $ENV{IS_MAINTAINER}; @@ -11,4 +10,4 @@ eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; -all_pod_coverage_ok( { trustme => [ qr/init_meta/ ] } ); +all_pod_coverage_ok( { trustme => [qr/init_meta/] } ); diff --git a/t/pod.t b/t/pod.t index 3f86494..f37ed3e 100644 --- a/t/pod.t +++ b/t/pod.t @@ -3,7 +3,6 @@ use warnings; use Test::More; - plan skip_all => 'This test is only run for the module author' unless -d '.svn' || $ENV{IS_MAINTAINER};