1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Exception/AggregateConfiguration.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Exception::AggregateConfiguration;
14 use Carp qw{ confess };
15 use English qw(-no_match_vars);
18 use Perl::Critic::Utils qw{ :characters };
20 our $VERSION = '1.088';
22 #-----------------------------------------------------------------------------
24 use Exception::Class (
25 'Perl::Critic::Exception::AggregateConfiguration' => {
26 isa => 'Perl::Critic::Exception',
27 description => 'A collected set of configuration exceptions.',
28 fields => [ qw{ exceptions } ],
29 alias => 'throw_aggregate',
33 #-----------------------------------------------------------------------------
35 Readonly::Array our @EXPORT_OK => qw< throw_aggregate >;
37 #-----------------------------------------------------------------------------
40 my ($class, %options) = @_;
42 my $exceptions = $options{exceptions};
43 if (not $exceptions) {
44 $options{exceptions} = [];
47 return $class->SUPER::new(%options);
50 #-----------------------------------------------------------------------------
53 my ( $self, $exception ) = @_;
55 push @{ $self->exceptions() }, $exception;
60 #-----------------------------------------------------------------------------
62 sub add_exceptions_from {
63 my ( $self, $aggregate ) = @_;
65 push @{ $self->exceptions() }, @{ $aggregate->exceptions() };
70 #-----------------------------------------------------------------------------
72 sub add_exception_or_rethrow {
73 my ( $self, $eval_error ) = @_;
75 return if not $eval_error;
76 confess $eval_error if not ref $eval_error; ## no critic (RequireUseOfExceptions)
78 if ( $eval_error->isa('Perl::Critic::Exception::Configuration') ) {
79 $self->add_exception($eval_error);
82 $eval_error->isa('Perl::Critic::Exception::AggregateConfiguration')
84 $self->add_exceptions_from($eval_error);
87 die $eval_error; ## no critic (RequireUseOfExceptions, RequireCarping)
93 #-----------------------------------------------------------------------------
98 return @{ $self->exceptions() } ? 1 : 0;
101 #-----------------------------------------------------------------------------
103 my $MESSAGE_PREFIX = $EMPTY;
104 my $MESSAGE_SUFFIX = "\n";
105 my $MESSAGE_SEPARATOR = $MESSAGE_SUFFIX . $MESSAGE_PREFIX;
110 my $message = $MESSAGE_PREFIX;
111 $message .= join $MESSAGE_SEPARATOR, @{ $self->exceptions() };
112 $message .= $MESSAGE_SUFFIX;
119 #-----------------------------------------------------------------------------
129 Perl::Critic::Exception::AggregateConfiguration - A collection of a set of problems found in the configuration and/or command-line options.
133 A set of configuration settings can have multiple problems. This is
134 an object for collecting all the problems found so that the user can
142 =item C<add_exception( $exception )>
144 Accumulate the parameter with rest of the exceptions.
147 =item C<add_exceptions_from( $aggregate )>
149 Accumulate the exceptions from another instance of this class.
152 =item C<exceptions()>
154 Returns a reference to an array of the collected exceptions.
157 =item C<add_exception_or_rethrow( $eval_error )>
159 If the parameter is an instance of
160 L<Perl::Critic::Exception::Configuration> or
161 L<Perl::Critic::Exception::AggregateConfiguration>, add it.
162 Otherwise, C<die> with the parameter, if it is a reference, or
163 C<confess> with it. If the parameter is false, simply returns.
166 =item C<has_exceptions()>
168 Answer whether any configuration problems have been found.
171 =item C<full_message()>
173 Concatenate the exception messages. See
174 L<Exception::Class/"full_message">.
182 Elliot Shank <perl@galumph.com>
186 Copyright (c) 2007-2008 Elliot Shank. All rights reserved.
188 This program is free software; you can redistribute it and/or modify
189 it under the same terms as Perl itself. The full text of this license
190 can be found in the LICENSE file included with this module.
194 ##############################################################################
197 # cperl-indent-level: 4
199 # indent-tabs-mode: nil
200 # c-indentation-style: bsd
202 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :