| 1 | package Perl::Critic::Policy::Moose::ProhibitDESTROYMethod; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '1.05'; | |||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Readonly (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Perl::Critic::Utils qw< :booleans :severities $EMPTY >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | Readonly::Scalar my $DESCRIPTION => | |||||||||
| 16 | q<"DESTROY" method/subroutine declared in a Moose class.>; | ||||||||||
| 17 | 1 | Readonly::Scalar my $EXPLANATION => q<Use DEMOLISH for your destructors.>; | |||||||||
| 18 | |||||||||||
| 19 | 6 | ▶ | sub supported_parameters { | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 20 | return ( | ||||||||||
| 21 | { | ||||||||||
| 22 | 6 | name => 'equivalent_modules', | |||||||||
| 23 | description => | ||||||||||
| 24 | q<The additional modules to treat as equivalent to "Moose", "Moose::Role", or "MooseX::Role::Parameterized".>, | ||||||||||
| 25 | behavior => 'string list', | ||||||||||
| 26 | list_always_present_values => | ||||||||||
| 27 | [qw< Moose Moose::Role MooseX::Role::Parameterized >], | ||||||||||
| 28 | }, | ||||||||||
| 29 | ); | ||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 3 | ▶ | sub default_severity { return $SEVERITY_MEDIUM; } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 33 | 0 | ▶ | sub default_themes { return qw< moose bugs >; } | ||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 34 | 6 | ▶ | sub applies_to { return 'PPI::Document' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 35 | |||||||||||
| 36 | 6 | ▶ | sub prepare_to_scan_document { | ||||||||
|
Subroutine
prepare_to_scan_document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | 6 | my ( $self, $document ) = @_; | |||||||||
| 38 | |||||||||||
| 39 | 6 | return $self->_is_interesting_document($document); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 13 | ▶ | sub _is_interesting_document { | ||||||||
|
Subroutine
_is_interesting_document: called CC=3 SCAR=11.0
| |||||||||||
| 43 | 13 | my ( $self, $document ) = @_; | |||||||||
| 44 | |||||||||||
| 45 | 13 | foreach my $module ( keys %{ $self->{_equivalent_modules} } ) { | |||||||||
| 46 | 25 | ▶ | return $TRUE if $document->uses_module($module); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 1 | return $FALSE; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 6 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 53 | 6 | my ( $self, undef, $document ) = @_; | |||||||||
| 54 | |||||||||||
| 55 | 6 | my @violations; | |||||||||
| 56 | 6 | foreach my $namespace ( $document->namespaces() ) { | |||||||||
| 57 | SUBDOCUMENT: | ||||||||||
| 58 | 7 | foreach my $subdocument ( | |||||||||
| 59 | $document->subdocuments_for_namespace($namespace) ) { | ||||||||||
| 60 | next SUBDOCUMENT | ||||||||||
| 61 | 7 | ▶ | if not $self->_is_interesting_document($subdocument); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | |||||||||||
| 63 | 6 | ▶ | if ( my $destructor | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | = $subdocument->find_first( \&_is_destructor ) ) { | ||||||||||
| 65 | 3 | push | |||||||||
| 66 | @violations, | ||||||||||
| 67 | $self->violation( | ||||||||||
| 68 | $DESCRIPTION, $EXPLANATION, | ||||||||||
| 69 | $destructor | ||||||||||
| 70 | ); | ||||||||||
| 71 | } | ||||||||||
| 72 | } | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 6 | return @violations; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 133 | ▶ | sub _is_destructor { | ||||||||
|
Subroutine
_is_destructor: called CC=2 SCAR=6.9
| |||||||||||
| 79 | 133 | my ( undef, $element ) = @_; | |||||||||
| 80 | |||||||||||
| 81 | 133 | ▶ | return $FALSE if not $element->isa('PPI::Statement::Sub'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | |||||||||||
| 83 | 5 | return $element->name() eq 'DESTROY'; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 1 | 1; | |||||||||
| 87 | |||||||||||
| 88 | # ABSTRACT: Use DEMOLISH instead of DESTROY | ||||||||||
| 89 | |||||||||||
| 90 | __END__ | ||||||||||