line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
XAO::Errors - throwable errors namespace support |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package XAO::Fubar; |
8
|
|
|
|
|
|
|
use XAO::Errors qw(XAO::Fubar); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub foo { |
11
|
|
|
|
|
|
|
... |
12
|
|
|
|
|
|
|
throw XAO::E::Fubar "foo - wrong arguments"; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Magic module that creates error namespaces for caller's. Should be |
18
|
|
|
|
|
|
|
used in situations like that. Say you create a XAO module called |
19
|
|
|
|
|
|
|
XAO::DO::Data::Product and want to throw errors from it. In order for |
20
|
|
|
|
|
|
|
these errors to be distinguishable you need separate namespace for |
21
|
|
|
|
|
|
|
them -- that's where XAO::Errors comes to rescue. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
In the bizarre case when you want more then one namespace for |
24
|
|
|
|
|
|
|
errors - you can pass these namespaces into XAO::Errors and it will |
25
|
|
|
|
|
|
|
make them throwable. It does not matter what to pass to XAO::Errors - |
26
|
|
|
|
|
|
|
the namespace of an error or the namespace of the package, the result |
27
|
|
|
|
|
|
|
would always go into XAO::E namespace. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
############################################################################### |
32
|
|
|
|
|
|
|
package XAO::Errors; |
33
|
14
|
|
|
14
|
|
112
|
use strict; |
|
14
|
|
|
|
|
88
|
|
|
14
|
|
|
|
|
488
|
|
34
|
14
|
|
|
14
|
|
3777
|
use Error; |
|
14
|
|
|
|
|
26159
|
|
|
14
|
|
|
|
|
91
|
|
35
|
|
|
|
|
|
|
|
36
|
14
|
|
|
14
|
|
1029
|
use vars qw($VERSION); |
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
1665
|
|
37
|
|
|
|
|
|
|
$VERSION=(0+sprintf('%u.%03u',(q$Id: Errors.pm,v 2.1 2005/01/13 22:34:34 am Exp $ =~ /\s(\d+)\.(\d+)\s/))) || die "Bad VERSION"; |
38
|
|
|
|
|
|
|
|
39
|
8
|
|
|
8
|
|
59
|
use vars qw(%errors_cache); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
2721
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub load_e_class ($) { |
42
|
44
|
|
|
44
|
0
|
99
|
my $module=shift; |
43
|
44
|
|
|
|
|
59
|
my $em; |
44
|
44
|
100
|
|
|
|
369
|
if($module=~/^XAO::E((::\w+)+)$/) { |
|
|
50
|
|
|
|
|
|
45
|
4
|
|
|
|
|
25
|
$em=$module; |
46
|
4
|
|
|
|
|
17
|
$module='XAO' . $1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif($module=~/^XAO((::\w+)+)$/) { |
49
|
40
|
|
|
|
|
145
|
$em='XAO::E' . $1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
0
|
|
|
|
|
0
|
throw Error::Simple "Can't import error module for $module"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
44
|
100
|
|
|
|
465
|
return $em if $errors_cache{$em}; |
56
|
|
|
|
|
|
|
|
57
|
8
|
50
|
|
8
|
|
66
|
eval <
|
|
8
|
50
|
|
8
|
|
61
|
|
|
8
|
50
|
|
8
|
|
226
|
|
|
8
|
0
|
|
8
|
|
63
|
|
|
8
|
|
|
8
|
|
19
|
|
|
8
|
|
|
8
|
|
41
|
|
|
8
|
|
|
8
|
|
618
|
|
|
8
|
|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|
|
|
|
use vars qw(\@ISA); |
63
|
|
|
|
|
|
|
\@ISA=qw(Error::Simple); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub throw { |
66
|
|
|
|
|
|
|
my \$self=shift; |
67
|
|
|
|
|
|
|
my \$text=join('',map { defined(\$_) ? \$_ : '' } \@_); |
68
|
|
|
|
|
|
|
\$self->SUPER::throw('${module}::' . \$text); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
END |
73
|
38
|
50
|
|
|
|
137
|
throw Error::Simple $@ if $@; |
74
|
38
|
|
|
|
|
98
|
$errors_cache{$em}=1; |
75
|
|
|
|
|
|
|
|
76
|
38
|
|
|
|
|
2517
|
return $em; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub import { |
80
|
44
|
|
|
44
|
|
1215
|
my $class=shift; |
81
|
44
|
|
|
|
|
151
|
my @list=@_; |
82
|
|
|
|
|
|
|
|
83
|
44
|
|
|
|
|
1344
|
foreach my $module (@list) { |
84
|
41
|
|
|
|
|
139
|
load_e_class($module); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub throw_by_class ($$$) { |
89
|
|
|
|
|
|
|
|
90
|
7
|
100
|
33
|
7
|
0
|
46
|
@_==2 || @_==3 || |
91
|
|
|
|
|
|
|
throw Error::Simple "throw_by_class - number of arguments is not 2 or 3"; |
92
|
|
|
|
|
|
|
|
93
|
7
|
50
|
|
|
|
28
|
my $self=(@_==3) ? shift : 'XAO::Errors'; |
94
|
7
|
|
|
|
|
25
|
my $class=shift; |
95
|
7
|
50
|
|
|
|
27
|
$class=ref($class) if ref($class); |
96
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
64
|
my $text=shift; |
98
|
|
|
|
|
|
|
|
99
|
4
|
|
|
|
|
30
|
my $em=load_e_class($class); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
## |
102
|
|
|
|
|
|
|
# Most probably will screw up stack trace, need to check and fix! |
103
|
|
|
|
|
|
|
# |
104
|
8
|
|
|
8
|
|
100
|
no strict 'refs'; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
563
|
|
105
|
4
|
|
|
|
|
172
|
$em->throw($text); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
############################################################################### |
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |