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
|
8
|
|
|
8
|
|
62
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
261
|
|
34
|
8
|
|
|
8
|
|
3946
|
use Error; |
|
8
|
|
|
|
|
27589
|
|
|
8
|
|
|
|
|
40
|
|
35
|
|
|
|
|
|
|
|
36
|
8
|
|
|
8
|
|
510
|
use vars qw($VERSION); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
667
|
|
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
|
|
56
|
use vars qw(%errors_cache); |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
2769
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub load_e_class ($) { |
42
|
44
|
|
|
44
|
0
|
138
|
my $module=shift; |
43
|
44
|
|
|
|
|
71
|
my $em; |
44
|
44
|
100
|
|
|
|
378
|
if($module=~/^XAO::E((::\w+)+)$/) { |
|
|
50
|
|
|
|
|
|
45
|
4
|
|
|
|
|
25
|
$em=$module; |
46
|
4
|
|
|
|
|
54
|
$module='XAO' . $1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif($module=~/^XAO((::\w+)+)$/) { |
49
|
40
|
|
|
|
|
152
|
$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
|
|
|
|
496
|
return $em if $errors_cache{$em}; |
56
|
|
|
|
|
|
|
|
57
|
8
|
50
|
|
8
|
|
61
|
eval <
|
|
8
|
50
|
|
8
|
|
46
|
|
|
8
|
50
|
|
8
|
|
245
|
|
|
8
|
50
|
|
8
|
|
49
|
|
|
8
|
0
|
|
8
|
|
14
|
|
|
8
|
50
|
|
8
|
|
34
|
|
|
8
|
|
|
8
|
|
663
|
|
|
8
|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13
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
38
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
268
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
24
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
42
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
18
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
package $em; |
60
|
|
|
|
|
|
|
use strict; |
61
|
|
|
|
|
|
|
use Error; |
62
|
|
|
|
|
|
|
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
|
|
|
|
135
|
throw Error::Simple $@ if $@; |
74
|
38
|
|
|
|
|
101
|
$errors_cache{$em}=1; |
75
|
|
|
|
|
|
|
|
76
|
38
|
|
|
|
|
2546
|
return $em; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub import { |
80
|
43
|
|
|
43
|
|
1052
|
my $class=shift; |
81
|
43
|
|
|
|
|
137
|
my @list=@_; |
82
|
|
|
|
|
|
|
|
83
|
43
|
|
|
|
|
1405
|
foreach my $module (@list) { |
84
|
40
|
|
|
|
|
110
|
load_e_class($module); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub throw_by_class ($$$) { |
89
|
|
|
|
|
|
|
|
90
|
4
|
50
|
33
|
4
|
0
|
55
|
@_==2 || @_==3 || |
91
|
|
|
|
|
|
|
throw Error::Simple "throw_by_class - number of arguments is not 2 or 3"; |
92
|
|
|
|
|
|
|
|
93
|
4
|
50
|
|
|
|
31
|
my $self=(@_==3) ? shift : 'XAO::Errors'; |
94
|
4
|
|
|
|
|
13
|
my $class=shift; |
95
|
4
|
50
|
|
|
|
23
|
$class=ref($class) if ref($class); |
96
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
56
|
my $text=shift; |
98
|
|
|
|
|
|
|
|
99
|
4
|
|
|
|
|
18
|
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
|
|
92
|
no strict 'refs'; |
|
8
|
|
|
|
|
26
|
|
|
8
|
|
|
|
|
579
|
|
105
|
4
|
|
|
|
|
202
|
$em->throw($text); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
############################################################################### |
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |