Login
Added svn keywords.
[gknop/Perl-Critic.git] / lib / Perl / Critic / Policy / BuiltinFunctions / ProhibitStringyEval.pm
CommitLineData
34167feb
JRT
1##################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##################################################################
7
59b05e08
JRT
8package Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval;
9
10use strict;
11use warnings;
12use Perl::Critic::Utils;
13use Perl::Critic::Violation;
14use base 'Perl::Critic::Policy';
15
16our $VERSION = '0.13';
17$VERSION = eval $VERSION; ## no critic
18
19my $desc = q{Expression form of 'eval'};
20my $expl = [161];
21
22#----------------------------------------------------------------------------
23
24sub violates {
25 my ( $self, $elem, $doc ) = @_;
26 $elem->isa('PPI::Token::Word') && $elem eq 'eval' || return;
27 return if is_hash_key($elem);
28
29 my $sib = $elem->snext_sibling() || return;
30 my $arg = $sib->isa('PPI::Structure::List') ? $sib->schild(0) : $sib;
31 return if !$arg || $arg->isa('PPI::Structure::Block');
32
33 #Must not be a block
34 return Perl::Critic::Violation->new( $desc, $expl, $elem->location() );
35}
36
37
381;
39
40__END__
41
42=head1 NAME
43
44Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval
45
46=head1 DESCRIPTION
47
48The string form of eval is recompiled every time it is executed,
49whereas the block form is only compiled once. Also, the string form
50doesn't give compile-time warnings.
51
52 eval "print $foo"; #not ok
53 eval {print $foo}; #ok
54
55=head1 SEE ALSO
56
57L<Perl::Critic::Policy::ControlStrucutres::ProhibitStringyGrep>
58
59L<Perl::Critic::Policy::ControlStrucutres::ProhibitStringyMap>
60
61=head1 AUTHOR
62
63Jeffrey Ryan Thalhammer <thaljef@cpan.org>
64
65Copyright (c) 2005 Jeffrey Ryan Thalhammer. All rights reserved.
66
67This program is free software; you can redistribute it and/or modify
68it under the same terms as Perl itself. The full text of this license
69can be found in the LICENSE file included with this module.