« blib/lib/Perl/Critic/Policy/Moose/ProhibitMultipleWiths.pm
↑ Summary
blib/lib/Perl/Critic/Moose.pm »
| 1 | # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-Moose/lib/Perl/Critic/Policy/Moose/RequireCleanNamespace.pm $ | ||||||||||
| 2 | # $Date: 2009-05-15 19:35:37 -0500 (Fri, 15 May 2009) $ | ||||||||||
| 3 | # $Author: clonezone $ | ||||||||||
| 4 | # $Revision: 3336 $ | ||||||||||
| 5 | |||||||||||
| 6 | package Perl::Critic::Policy::Moose::RequireCleanNamespace; | ||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use 5.008; # Moose's minimum version. | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | our $VERSION = '0.999_002'; | |||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use Readonly (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | ▶ | use Perl::Critic::Utils qw< :booleans :severities $PERIOD >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | 1 | Readonly::Scalar my $EXPLANATION => | |||||||||
| 23 | q<Don't leave things used for implementation in your interface.>; | ||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | sub supported_parameters { | ||||||||||
| 27 | return ( | ||||||||||
| 28 | { | ||||||||||
| 29 | 8 | ▶ | name => 'modules', | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | description => 'The modules that need to be unimported.', | ||||||||||
| 31 | default_string => | ||||||||||
| 32 | 'Moose Moose::Role Moose::Util::TypeConstraints', | ||||||||||
| 33 | behavior => 'string list', | ||||||||||
| 34 | }, | ||||||||||
| 35 | ); | ||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 4 | ▶ | sub default_severity { return $SEVERITY_MEDIUM; } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 39 | 0 | ▶ | sub default_themes { return qw( moose maintenance ); } | ||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 40 | 8 | ▶ | sub applies_to { return 'PPI::Document' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | sub violates { | ||||||||||
| 44 | 8 | ▶ | my ($self, undef, $document) = @_; | ||||||||
|
Subroutine
violates: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||
| 45 | |||||||||||
| 46 | 8 | my %modules = ( use => {}, require => {}, no => {} ); | |||||||||
| 47 | 8 | my $includes = $document->find('PPI::Statement::Include'); | |||||||||
| 48 | 8 | ▶ | return if not $includes; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | 8 | for my $include ( @{$includes} ) { | |||||||||
| 51 | 15 | $modules{$include->type}->{$include->module} = 1; | |||||||||
| 52 | } # end for | ||||||||||
| 53 | |||||||||||
| 54 | 8 | my $modules_to_unimport = $self->{_modules}; | |||||||||
| 55 | my @used_but_not_unimported = | ||||||||||
| 56 | 10 | ▶ | grep { $modules_to_unimport->{$_} and not $modules{no}->{$_} } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 8 | keys %{ $modules{use} }; | |||||||||
| 58 | |||||||||||
| 59 | 8 | ▶ | return if not @used_but_not_unimported; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | |||||||||||
| 61 | 4 | return $self->violation( | |||||||||
| 62 | q<Didn't unimport > . (join q<, >, sort @used_but_not_unimported) . $PERIOD, | ||||||||||
| 63 | $EXPLANATION, | ||||||||||
| 64 | $document, | ||||||||||
| 65 | ); | ||||||||||
| 66 | } # end violates() | ||||||||||
| 67 | |||||||||||
| 68 | |||||||||||
| 69 | 1 | 1; | |||||||||
| 70 | |||||||||||
| 71 | __END__ | ||||||||||
| 72 | |||||||||||
| 73 | =pod | ||||||||||
| 74 | |||||||||||
| 75 | =for stopwords unimport | ||||||||||
| 76 | |||||||||||
| 77 | =head1 NAME | ||||||||||
| 78 | |||||||||||
| 79 | Perl::Critic::Policy::Moose::RequireCleanNamespace - Require removing implementation details from you packages. | ||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | =head1 AFFILIATION | ||||||||||
| 83 | |||||||||||
| 84 | This policy is part of L<Perl::Critic::Moose>. | ||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | =head1 VERSION | ||||||||||
| 88 | |||||||||||
| 89 | This document describes Perl::Critic::Policy::Moose::RequireCleanNamespace | ||||||||||
| 90 | version 0.999_002. | ||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | =head1 DESCRIPTION | ||||||||||
| 94 | |||||||||||
| 95 | Anything in your namespace is part of your interface. The L<Moose> sugar is | ||||||||||
| 96 | an implementation detail and not part of what you want to support as part of | ||||||||||
| 97 | your functionality, especially if you may change your implementation to not | ||||||||||
| 98 | use Moose in the future. Thus, this policy requires you to say C<no Moose;> | ||||||||||
| 99 | or C<no Moose::Role;>, etc. as appropriate for modules you C<use>. | ||||||||||
| 100 | |||||||||||
| 101 | |||||||||||
| 102 | =head1 CONFIGURATION | ||||||||||
| 103 | |||||||||||
| 104 | By default, this module will complain if you C<use> L<Moose>, L<Moose::Role>, | ||||||||||
| 105 | or C<Moose::Util::TypeConstraints> but don't unimport them. You can set the | ||||||||||
| 106 | modules looked for using the C<modules> option. | ||||||||||
| 107 | |||||||||||
| 108 | [Moose::RequireCleanNamespace] | ||||||||||
| 109 | modules = Moose Moose::Role Moose::Util::TypeConstraints MooseX::My::New::Sugar | ||||||||||
| 110 | |||||||||||
| 111 | |||||||||||
| 112 | =head1 SEE ALSO | ||||||||||
| 113 | |||||||||||
| 114 | L<http://search.cpan.org/dist/Moose/lib/Moose/Manual/BestPractices.pod#no_Moose_and_immutabilize> | ||||||||||
| 115 | |||||||||||
| 116 | |||||||||||
| 117 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 118 | |||||||||||
| 119 | Right now this assumes that you've only got one C<package> statement in your | ||||||||||
| 120 | code. It will get things wrong if you create multiple classes in a single | ||||||||||
| 121 | file. | ||||||||||
| 122 | |||||||||||
| 123 | This doesn't support using L<namespace::clean>. | ||||||||||
| 124 | |||||||||||
| 125 | Please report any bugs or feature requests to | ||||||||||
| 126 | C<bug-perl-critic-moose@rt.cpan.org>, or through the web interface at | ||||||||||
| 127 | L<http://rt.cpan.org>. | ||||||||||
| 128 | |||||||||||
| 129 | |||||||||||
| 130 | =head1 AUTHOR | ||||||||||
| 131 | |||||||||||
| 132 | Elliot Shank C<< <perl@galumph.com> >> | ||||||||||
| 133 | |||||||||||
| 134 | |||||||||||
| 135 | =head1 COPYRIGHT | ||||||||||
| 136 | |||||||||||
| 137 | Copyright (c)2008-2009, Elliot Shank C<< <perl@galumph.com> >>. Some rights | ||||||||||
| 138 | reserved. | ||||||||||
| 139 | |||||||||||
| 140 | This module is free software; you can redistribute it and/or modify it under | ||||||||||
| 141 | the same terms as Perl itself. See L<perlartistic>. | ||||||||||
| 142 | |||||||||||
| 143 | |||||||||||
| 144 | =head1 DISCLAIMER OF WARRANTY | ||||||||||
| 145 | |||||||||||
| 146 | BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE | ||||||||||
| 147 | SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE | ||||||||||
| 148 | STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE | ||||||||||
| 149 | SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, | ||||||||||
| 150 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||||||||||
| 151 | FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND | ||||||||||
| 152 | PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, | ||||||||||
| 153 | YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. | ||||||||||
| 154 | |||||||||||
| 155 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY | ||||||||||
| 156 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE | ||||||||||
| 157 | SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, | ||||||||||
| 158 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING | ||||||||||
| 159 | OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO | ||||||||||
| 160 | LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR | ||||||||||
| 161 | THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER | ||||||||||
| 162 | SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | ||||||||||
| 163 | POSSIBILITY OF SUCH DAMAGES. | ||||||||||
| 164 | |||||||||||
| 165 | |||||||||||
| 166 | =cut | ||||||||||
| 167 | |||||||||||
| 168 | # Local Variables: | ||||||||||
| 169 | # mode: cperl | ||||||||||
| 170 | # cperl-indent-level: 4 | ||||||||||
| 171 | # fill-column: 78 | ||||||||||
| 172 | # indent-tabs-mode: nil | ||||||||||
| 173 | # c-indentation-style: bsd | ||||||||||
| 174 | # End: | ||||||||||
| 175 | # setup vim: set filetype=perl tabstop=4 softtabstop=4 expandtab : | ||||||||||
| 176 | # setup vim: set shiftwidth=4 shiftround textwidth=78 autoindent : | ||||||||||
| 177 | # setup vim: set foldmethod=indent foldlevel=0 : | ||||||||||