Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / ClassHierarchies / ProhibitOneArgBless.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ClassHierarchies/ProhibitOneArgBless.pm $
3 #     $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::ClassHierarchies::ProhibitOneArgBless;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :booleans :severities :classification :ppi };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{One-argument "bless" used};
23 Readonly::Scalar my $EXPL => [ 365 ];
24
25 #-----------------------------------------------------------------------------
26
27 sub supported_parameters { return ()                  }
28 sub default_severity     { return $SEVERITY_HIGHEST   }
29 sub default_themes       { return qw( core pbp bugs ) }
30 sub applies_to           { return 'PPI::Token::Word'  }
31
32 #-----------------------------------------------------------------------------
33
34 sub violates {
35     my ($self, $elem, undef) = @_;
36
37     return if $elem ne 'bless';
38     return if ! is_function_call($elem);
39
40     if( scalar parse_arg_list($elem) == 1 ) {
41         return $self->violation( $DESC, $EXPL, $elem );
42     }
43     return; #ok!
44 }
45
46 1;
47
48 #-----------------------------------------------------------------------------
49
50 __END__
51
52 =pod
53
54 =head1 NAME
55
56 Perl::Critic::Policy::ClassHierarchies::ProhibitOneArgBless - Write C<bless {}, $class;> instead of just C<bless {};>.
57
58 =head1 AFFILIATION
59
60 This Policy is part of the core L<Perl::Critic> distribution.
61
62
63 =head1 DESCRIPTION
64
65 Always use the two-argument form of C<bless> because it allows
66 subclasses to inherit your constructor.
67
68   sub new {
69       my $class = shift;
70       my $self = bless {};          # not ok
71       my $self = bless {}, $class;  # ok
72       return $self;
73   }
74
75
76 =head1 CONFIGURATION
77
78 This Policy is not configurable except for the standard options.
79
80
81 =head1 AUTHOR
82
83 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
84
85 =head1 COPYRIGHT
86
87 Copyright (C) 2005-2007 Jeffrey Ryan Thalhammer.  All rights reserved.
88
89 This program is free software; you can redistribute it and/or modify
90 it under the same terms as Perl itself.
91
92 =cut
93
94 # Local Variables:
95 #   mode: cperl
96 #   cperl-indent-level: 4
97 #   fill-column: 78
98 #   indent-tabs-mode: nil
99 #   c-indentation-style: bsd
100 # End:
101 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :