1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
use strict;
use warnings;
=head1 NAME
Config:Scoped::Error - an exception class hierarchy based on Error.pm for Config::Scoped
=head1 SYNOPSIS
use Config::Scoped::Error;
Config::Scoped::Error::Parse->throw(
-text => $parser_error,
-file => $config_file,
-line => $thisline,
);
Config::Scoped::Error::IO->throw(
-text => "can't open file: $!",
-file => $config_file,
-line => $thisline,
);
Config::Scoped::Error::Validate::Macro->throw(
-text => "macro redefinition: $macro_name",
-file => $config_file,
-line => $thisline,
);
=head1 DESCRIPTION
Config::Scoped::Error is a class hierarchy based on Error.pm. The following Exception class hierarchy is defined:
Config::Scoped::Error
Config::Scoped::Error::Parse
Config::Scoped::Error::Validate
Config::Scoped::Error::Validate::Macro
Config::Scoped::Error::Validate::Parameter
Config::Scoped::Error::Validate::Declaration
Config::Scoped::Error::Validate::Permissions
Config::Scoped::Error::IO
=cut
package Config::Scoped::Error;
use base 'Error';
our $VERSION='0.12';
#Error propagation, see perldoc -f die
sub PROPAGATE {
no warnings 'uninitialized';
$_[0]->{-propagate} .= "propagated at $_[1] line $_[2]\n";
return $_[0];
}
# private accessor
sub _propagate {
return exists $_[0]->{-propagate} ? $_[0]->{-propagate} : undef;
}
# Override Error::stringify.
# Add the file and line if not ending in a newline and
# add the propagated text.
sub stringify {
no warnings 'uninitialized';
my $file = $_[0]->file;
my $line = $_[0]->line;
my $propagate = $_[0]->_propagate || '';
my $text = $_[0]->SUPER::stringify;
$text .= " at $file line $line.\n"
unless ( $text =~ /\n$/s );
$text .= $propagate;
return $text;
}
package Config::Scoped::Error::Parse;
use base 'Config::Scoped::Error';
our $VERSION='0.12';
package Config::Scoped::Error::IO;
use base 'Config::Scoped::Error';
our $VERSION='0.12';
package Config::Scoped::Error::Validate;
use base 'Config::Scoped::Error';
our $VERSION='0.12';
package Config::Scoped::Error::Validate::Macro;
use base 'Config::Scoped::Error::Validate';
our $VERSION='0.12';
package Config::Scoped::Error::Validate::Parameter;
use base 'Config::Scoped::Error::Validate';
our $VERSION='0.12';
package Config::Scoped::Error::Validate::Declaration;
use base 'Config::Scoped::Error::Validate';
our $VERSION='0.12';
package Config::Scoped::Error::Validate::Permissions;
use base 'Config::Scoped::Error::Validate';
our $VERSION='0.12';
1;
=head1 SEE ALSO
Config::Scoped, Error
=head1 AUTHOR
Karl Gaissmaier E<lt>karl.gaissmaier at uni-ulm.deE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2004-2008 by Karl Gaissmaier
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# vim: cindent sm nohls sw=4 sts=4 ruler
|