From: gfx Date: Fri, 12 Mar 2010 07:06:32 +0000 (+0900) Subject: Introduce Test::Perl::Critic X-Git-Tag: 0.50_09~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a4b15169d428989d2e901708effe21f3eaab23b5;p=gitmo%2FMouse.git Introduce Test::Perl::Critic --- diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 9aa79ad..34e9ce8 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -345,7 +345,9 @@ sub install_accessors{ return; } -sub delegation_metaclass() { 'Mouse::Meta::Method::Delegation' } +sub delegation_metaclass() { ## no critic + 'Mouse::Meta::Method::Delegation' +} sub _canonicalize_handles { my($self, $handles) = @_; diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 0ba039e..639404b 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -129,7 +129,7 @@ sub _collect_roles { } my %seen; - return sort grep { !$seen{$_}++ } + return sort grep { !$seen{$_}++ } ## no critic (map{ $_->name } map{ $_->meta->calculate_all_roles } @self_anon_supers), (map{ $_->name } map{ $_->meta->calculate_all_roles } @other_anon_supers), ; diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 01e0da5..ebf6011 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -1,9 +1,11 @@ package Mouse::Util; use Mouse::Exporter; # enables strict and warnings -sub get_linear_isa($;$); # must be here +# must be here because it will be refered by other modules loaded +sub get_linear_isa($;$); ## no critic -sub install_subroutines { # must be here +# must be here because it will called in Mouse::Exporter +sub install_subroutines { my $into = shift; while(my($name, $code) = splice @_, 0, 2){ diff --git a/lib/Mouse/Util/TypeConstraints.pm b/lib/Mouse/Util/TypeConstraints.pm index f309ec7..225cefe 100644 --- a/lib/Mouse/Util/TypeConstraints.pm +++ b/lib/Mouse/Util/TypeConstraints.pm @@ -82,13 +82,13 @@ $TYPE{HashRef} {constraint_generator} = \&_parameterize_HashRef_for; # sugars -sub as ($) { (as => $_[0]) } -sub where (&) { (where => $_[0]) } -sub message (&) { (message => $_[0]) } -sub optimize_as (&) { (optimize_as => $_[0]) } +sub as ($) { (as => $_[0]) } ## no critic +sub where (&) { (where => $_[0]) } ## no critic +sub message (&) { (message => $_[0]) } ## no critic +sub optimize_as (&) { (optimize_as => $_[0]) } ## no critic sub from { @_ } -sub via (&) { $_[0] } +sub via (&) { $_[0] } ## no critic # type utilities diff --git a/lib/Test/Mouse.pm b/lib/Test/Mouse.pm index a9583bf..6bf1ba7 100644 --- a/lib/Test/Mouse.pm +++ b/lib/Test/Mouse.pm @@ -20,7 +20,7 @@ my $Test = Test::Builder->new; ## exported functions -sub meta_ok ($;$) { +sub meta_ok ($;$) { ## no critic my ($class_or_obj, $message) = @_; $message ||= "The object has a meta"; @@ -33,7 +33,7 @@ sub meta_ok ($;$) { } } -sub does_ok ($$;$) { +sub does_ok ($$;$) { ## no critic my ($class_or_obj, $does, $message) = @_; $message ||= "The object does $does"; @@ -46,7 +46,7 @@ sub does_ok ($$;$) { } } -sub has_attribute_ok ($$;$) { +sub has_attribute_ok ($$;$) { ## no critic my ($class_or_obj, $attr_name, $message) = @_; $message ||= "The object does has an attribute named $attr_name"; @@ -61,7 +61,7 @@ sub has_attribute_ok ($$;$) { } } -sub with_immutable (&@) { +sub with_immutable (&@) { ## no critic my $block = shift; my $before = $Test->current_test; diff --git a/lib/ouse.pm b/lib/ouse.pm index 0173553..a932c66 100644 --- a/lib/ouse.pm +++ b/lib/ouse.pm @@ -2,17 +2,16 @@ package ouse; use Mouse::Util; # enables strict and warnings -BEGIN { - my $package; - sub import { - $package = $_[1] || 'Class'; - if ($package =~ /^\+/) { - $package =~ s/^\+//; - Mouse::Util::load_class($package); - } + +my $package = 'Class'; +sub import { + $package = $_[1] || 'Class'; + if ($package =~ /^\+/) { + $package =~ s/^\+//; + Mouse::Util::load_class($package); } - use Filter::Simple sub { s/^/package $package;\nuse Mouse;\nuse Mouse::Util::TypeConstraints;\n/; } } +use Filter::Simple sub { s/^/package $package;\nuse Mouse;\nuse Mouse::Util::TypeConstraints;\n/; }; 1; __END__ diff --git a/tool/generate-mouse-tiny.pl b/tool/generate-mouse-tiny.pl index 045387d..cd9389a 100644 --- a/tool/generate-mouse-tiny.pl +++ b/tool/generate-mouse-tiny.pl @@ -68,7 +68,8 @@ print { $handle } << "EOF"; # This file was generated by $0 from Mouse $Mouse::Spec::VERSION. # # ANY CHANGES MADE HERE WILL BE LOST! - +use strict; +use warnings; EOF print { $handle } << 'EOF'; diff --git a/xt/08_perlcritic.t b/xt/08_perlcritic.t new file mode 100644 index 0000000..aa45885 --- /dev/null +++ b/xt/08_perlcritic.t @@ -0,0 +1,25 @@ +use strict; +use Test::More; +eval { + require Perl::Critic; + Perl::Critic->VERSION(1.105); + + require Test::Perl::Critic; + Test::Perl::Critic->import( -profile => \join q{}, ); +}; +plan skip_all => "Test::Perl::Critic is not installed." if $@; +all_critic_ok('lib'); + +__END__ + +exclude=ProhibitStringyEval ProhibitExplicitReturnUndef RequireBarewordIncludes + +[TestingAndDebugging::ProhibitNoStrict] +allow=refs + +[TestingAndDebugging::RequireUseStrict] +equivalent_modules = Mouse Mouse::Exporter Mouse::Util Mouse::Util::TypeConstraints + +[TestingAndDebugging::RequireUseWarnings] +equivalent_modules = Mouse Mouse::Exporter Mouse::Util Mouse::Util::TypeConstraints +