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) $
6 ##############################################################################
8 package Perl::Critic::Policy::ClassHierarchies::ProhibitOneArgBless;
15 use Perl::Critic::Utils qw{ :booleans :severities :classification :ppi };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{One-argument "bless" used};
23 Readonly::Scalar my $EXPL => [ 365 ];
25 #-----------------------------------------------------------------------------
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' }
32 #-----------------------------------------------------------------------------
35 my ($self, $elem, undef) = @_;
37 return if $elem ne 'bless';
38 return if ! is_function_call($elem);
40 if( scalar parse_arg_list($elem) == 1 ) {
41 return $self->violation( $DESC, $EXPL, $elem );
48 #-----------------------------------------------------------------------------
56 Perl::Critic::Policy::ClassHierarchies::ProhibitOneArgBless - Write C<bless {}, $class;> instead of just C<bless {};>.
60 This Policy is part of the core L<Perl::Critic> distribution.
65 Always use the two-argument form of C<bless> because it allows
66 subclasses to inherit your constructor.
70 my $self = bless {}; # not ok
71 my $self = bless {}, $class; # ok
78 This Policy is not configurable except for the standard options.
83 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
87 Copyright (C) 2005-2007 Jeffrey Ryan Thalhammer. All rights reserved.
89 This program is free software; you can redistribute it and/or modify
90 it under the same terms as Perl itself.
96 # cperl-indent-level: 4
98 # indent-tabs-mode: nil
99 # c-indentation-style: bsd
101 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :