| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Modules/RequireExplicitPackage.pm |
| Statements | Executed 18 statements in 465µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 16µs | 16µs | Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@10 |
| 1 | 1 | 1 | 10µs | 435µs | Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@15 |
| 1 | 1 | 1 | 8µs | 11µs | Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@12 |
| 1 | 1 | 1 | 7µs | 57µs | Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@16 |
| 1 | 1 | 1 | 7µs | 27µs | Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@13 |
| 1 | 1 | 1 | 7µs | 18µs | Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@11 |
| 1 | 1 | 1 | 7µs | 7µs | Perl::Critic::Policy::Modules::RequireExplicitPackage::supported_parameters |
| 1 | 1 | 1 | 6µs | 8µs | Perl::Critic::Policy::Modules::RequireExplicitPackage::default_severity |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Modules::RequireExplicitPackage::_is_statement_of_interest |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Modules::RequireExplicitPackage::applies_to |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Modules::RequireExplicitPackage::default_maximum_violations_per_document |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Modules::RequireExplicitPackage::default_themes |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Modules::RequireExplicitPackage::prepare_to_scan_document |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::Modules::RequireExplicitPackage::violates |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | ############################################################################## | ||||
| 2 | # $URL$ | ||||
| 3 | # $Date$ | ||||
| 4 | # $Author$ | ||||
| 5 | # $Revision$ | ||||
| 6 | ############################################################################## | ||||
| 7 | |||||
| 8 | package Perl::Critic::Policy::Modules::RequireExplicitPackage; | ||||
| 9 | |||||
| 10 | 2 | 39µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@10 which was called:
# once (16µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 16µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@10 |
| 11 | 2 | 20µs | 2 | 29µs | # spent 18µs (7+11) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@11 which was called:
# once (7µs+11µs) by Module::Pluggable::Object::_require at line 11 # spent 18µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@11
# spent 11µs making 1 call to strict::import |
| 12 | 2 | 18µs | 2 | 15µs | # spent 11µs (8+4) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@12 which was called:
# once (8µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 11µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@12
# spent 4µs making 1 call to warnings::import |
| 13 | 2 | 25µs | 2 | 47µs | # spent 27µs (7+20) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@13 which was called:
# once (7µs+20µs) by Module::Pluggable::Object::_require at line 13 # spent 27µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
| 14 | |||||
| 15 | 2 | 24µs | 2 | 860µs | # spent 435µs (10+425) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@15 which was called:
# once (10µs+425µs) by Module::Pluggable::Object::_require at line 15 # spent 435µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@15
# spent 425µs making 1 call to Exporter::import |
| 16 | 2 | 322µs | 2 | 106µs | # spent 57µs (7+49) within Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@16 which was called:
# once (7µs+49µs) by Module::Pluggable::Object::_require at line 16 # spent 57µs making 1 call to Perl::Critic::Policy::Modules::RequireExplicitPackage::BEGIN@16
# spent 49µs making 1 call to base::import |
| 17 | |||||
| 18 | 1 | 600ns | our $VERSION = '1.121'; | ||
| 19 | |||||
| 20 | #----------------------------------------------------------------------------- | ||||
| 21 | |||||
| 22 | 1 | 2µs | 1 | 28µs | Readonly::Scalar my $EXPL => q{Violates encapsulation}; # spent 28µs making 1 call to Readonly::Scalar |
| 23 | 1 | 900ns | 1 | 21µs | Readonly::Scalar my $DESC => q{Code not contained in explicit package}; # spent 21µs making 1 call to Readonly::Scalar |
| 24 | |||||
| 25 | #----------------------------------------------------------------------------- | ||||
| 26 | |||||
| 27 | # spent 7µs within Perl::Critic::Policy::Modules::RequireExplicitPackage::supported_parameters which was called:
# once (7µs+0s) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
| 28 | return ( | ||||
| 29 | { | ||||
| 30 | 1 | 9µs | name => 'exempt_scripts', | ||
| 31 | description => q{Don't require programs to contain a package statement.}, | ||||
| 32 | default_string => '1', | ||||
| 33 | behavior => 'boolean', | ||||
| 34 | }, | ||||
| 35 | { | ||||
| 36 | name => 'allow_import_of', | ||||
| 37 | description => q{Allow the specified modules to be imported outside a package}, | ||||
| 38 | behavior => 'string list', | ||||
| 39 | }, | ||||
| 40 | ); | ||||
| 41 | } | ||||
| 42 | |||||
| 43 | 1 | 2µs | # spent 8µs (6+1) within Perl::Critic::Policy::Modules::RequireExplicitPackage::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
| 44 | sub default_themes { return qw( core bugs ) } | ||||
| 45 | sub applies_to { return 'PPI::Document' } | ||||
| 46 | |||||
| 47 | sub default_maximum_violations_per_document { return 1; } | ||||
| 48 | |||||
| 49 | #----------------------------------------------------------------------------- | ||||
| 50 | |||||
| 51 | sub prepare_to_scan_document { | ||||
| 52 | my ( $self, $document ) = @_; | ||||
| 53 | |||||
| 54 | return ! $self->{_exempt_scripts} || $document->is_module(); | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | sub violates { | ||||
| 58 | my ( $self, $elem, $doc ) = @_; | ||||
| 59 | |||||
| 60 | # Find the first 'package' statement | ||||
| 61 | my $package_stmnt = $doc->find_first( 'PPI::Statement::Package' ); | ||||
| 62 | my $package_line = $package_stmnt ? $package_stmnt->location()->[0] : undef; | ||||
| 63 | |||||
| 64 | # Find all statements that aren't 'package' statements | ||||
| 65 | my $stmnts_ref = $doc->find( 'PPI::Statement' ); | ||||
| 66 | return if !$stmnts_ref; | ||||
| 67 | my @non_packages = grep { | ||||
| 68 | $self->_is_statement_of_interest( $_ ) | ||||
| 69 | } @{$stmnts_ref}; | ||||
| 70 | return if !@non_packages; | ||||
| 71 | |||||
| 72 | # If the 'package' statement is not defined, or the other | ||||
| 73 | # statements appear before the 'package', then it violates. | ||||
| 74 | |||||
| 75 | my @viols = (); | ||||
| 76 | for my $stmnt ( @non_packages ) { | ||||
| 77 | my $stmnt_line = $stmnt->location()->[0]; | ||||
| 78 | if ( (! defined $package_line) || ($stmnt_line < $package_line) ) { | ||||
| 79 | push @viols, $self->violation( $DESC, $EXPL, $stmnt ); | ||||
| 80 | } | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | return @viols; | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | sub _is_statement_of_interest { | ||||
| 87 | my ( $self, $elem ) = @_; | ||||
| 88 | |||||
| 89 | $elem | ||||
| 90 | or return $FALSE; | ||||
| 91 | |||||
| 92 | $elem->isa( 'PPI::Statement::Package' ) | ||||
| 93 | and return $FALSE; | ||||
| 94 | |||||
| 95 | if ( $elem->isa( 'PPI::Statement::Include' ) ) { | ||||
| 96 | if ( my $module = $elem->module() ) { | ||||
| 97 | $self->{_allow_import_of}{$module} | ||||
| 98 | and return $FALSE; | ||||
| 99 | } | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | return $TRUE; | ||||
| 103 | } | ||||
| 104 | |||||
| 105 | 1 | 3µs | 1; | ||
| 106 | |||||
| 107 | __END__ |