1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/OptionsProcessor.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::OptionsProcessor;
14 use English qw(-no_match_vars);
16 use Perl::Critic::Exception::AggregateConfiguration;
17 use Perl::Critic::Exception::Configuration::Option::Global::ExtraParameter;
18 use Perl::Critic::Utils qw<
19 :booleans :characters :severities :data_conversion $DEFAULT_VERBOSITY
21 use Perl::Critic::Utils::Constants qw< $PROFILE_STRICTNESS_DEFAULT >;
22 use Perl::Critic::Utils::DataConversion qw< dor >;
24 our $VERSION = '1.088';
26 #-----------------------------------------------------------------------------
29 my ($class, %args) = @_;
30 my $self = bless {}, $class;
31 $self->_init( %args );
35 #-----------------------------------------------------------------------------
38 my ( $self, %args ) = @_;
40 # Multi-value defaults
41 my $exclude = dor(delete $args{exclude}, $EMPTY);
42 $self->{_exclude} = [ words_from_string( $exclude ) ];
43 my $include = dor(delete $args{include}, $EMPTY);
44 $self->{_include} = [ words_from_string( $include ) ];
46 # Single-value defaults
47 $self->{_force} = dor(delete $args{force}, $FALSE);
48 $self->{_only} = dor(delete $args{only}, $FALSE);
49 $self->{_profile_strictness} =
50 dor(delete $args{'profile-strictness'}, $PROFILE_STRICTNESS_DEFAULT);
51 $self->{_single_policy} = dor(delete $args{'single-policy'}, $EMPTY);
52 $self->{_severity} = dor(delete $args{severity}, $SEVERITY_HIGHEST);
53 $self->{_theme} = dor(delete $args{theme}, $EMPTY);
54 $self->{_top} = dor(delete $args{top}, $FALSE);
55 $self->{_verbose} = dor(delete $args{verbose}, $DEFAULT_VERBOSITY);
56 $self->{_criticism_fatal} = dor(delete $args{'criticism-fatal'}, $FALSE);
58 $self->{_color} = dor(delete $args{color}, dor(delete $args{colour}, $TRUE));
60 # If there's anything left, complain.
61 _check_for_extra_options(%args);
66 #-----------------------------------------------------------------------------
68 sub _check_for_extra_options {
71 if ( my @remaining = sort keys %args ){
72 my $errors = Perl::Critic::Exception::AggregateConfiguration->new();
74 foreach my $option_name (@remaining) {
75 $errors->add_exception(
76 Perl::Critic::Exception::Configuration::Option::Global::ExtraParameter->new(
77 option_name => $option_name,
88 #-----------------------------------------------------------------------------
89 # Public ACCESSOR methods
93 return $self->{_severity};
96 #-----------------------------------------------------------------------------
100 return $self->{_theme};
103 #-----------------------------------------------------------------------------
107 return $self->{_exclude};
110 #-----------------------------------------------------------------------------
114 return $self->{_include};
117 #-----------------------------------------------------------------------------
121 return $self->{_only};
124 #-----------------------------------------------------------------------------
126 sub profile_strictness {
128 return $self->{_profile_strictness};
131 #-----------------------------------------------------------------------------
135 return $self->{_single_policy};
138 #-----------------------------------------------------------------------------
142 return $self->{_verbose};
145 #-----------------------------------------------------------------------------
149 return $self->{_color};
152 #-----------------------------------------------------------------------------
154 sub criticism_fatal {
156 return $self->{_criticism_fatal};
159 #-----------------------------------------------------------------------------
163 return $self->{_force};
166 #-----------------------------------------------------------------------------
170 return $self->{_top};
178 #-----------------------------------------------------------------------------
184 Perl::Critic::OptionsProcessor - The global configuration default values, combined with command-line values.
188 This is a helper class that encapsulates the default parameters for
189 constructing a L<Perl::Critic::Config> object. There are no
190 user-serviceable parts here.
196 =item C< new( %DEFAULT_PARAMS ) >
198 Returns a reference to a new C<Perl::Critic::OptionsProcessor> object. You
199 can override the coded defaults by passing in name-value pairs that
200 correspond to the methods listed below.
202 This is usually only invoked by L<Perl::Critic::UserProfile>, which
203 passes in the global values from a F<.perlcriticrc> file. This object
204 contains no information for individual Policies.
214 Returns a reference to a list of the default exclusion patterns. If
215 there are no default exclusion patterns, then the list will be empty.
219 Returns the default value of the C<force> flag (Either 1 or 0).
223 Returns a reference to a list of the default inclusion patterns. If
224 there are no default exclusion patterns, then the list will be empty.
228 Returns the default value of the C<only> flag (Either 1 or 0).
230 =item C< profile_strictness() >
232 Returns the default value of C<profile_strictness> as an unvalidated
235 =item C< single_policy() >
237 Returns the default C<single-policy> pattern. (As a string.)
239 =item C< severity() >
241 Returns the default C<severity> setting. (1..5).
245 Returns the default C<theme> setting. (As a string).
249 Returns the default C<top> setting. (Either 0 or a positive integer).
253 Returns the default C<verbose> setting. (Either a number or format
258 Returns the default C<color> setting. (Either 1 or 0).
260 =item C< criticism_fatal() >
262 Returns the default C<criticism-fatal> setting (Either 1 or 0).
268 L<Perl::Critic::Config>, L<Perl::Critic::UserProfile>
272 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
276 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
278 This program is free software; you can redistribute it and/or modify
279 it under the same terms as Perl itself. The full text of this license
280 can be found in the LICENSE file included with this module.
286 # cperl-indent-level: 4
288 # indent-tabs-mode: nil
289 # c-indentation-style: bsd
291 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :