line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -c |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Exception::Assertion; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Exception::Assertion - Thrown when assertion failed |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Exception::Assertion; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub assert_foo { |
14
|
|
|
|
|
|
|
my $self = eval { $_[0]->isa(__PACKAGE__) } ? shift : __PACKAGE__; |
15
|
|
|
|
|
|
|
my ($condition, $message) = @_; |
16
|
|
|
|
|
|
|
Exception::Assertion->throw( |
17
|
|
|
|
|
|
|
message => $message, |
18
|
|
|
|
|
|
|
reason => 'foo failed', |
19
|
|
|
|
|
|
|
) unless $condition; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
assert_foo( 0, 'assert_foo failed' ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This class extends standard L and is thrown when assertion is |
27
|
|
|
|
|
|
|
failed. It contains additional attribute C which represents detailed |
28
|
|
|
|
|
|
|
message about reason of failed assertion. The exception has also raised |
29
|
|
|
|
|
|
|
verbosity. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
4
|
|
2964
|
use 5.006; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
168
|
|
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
140
|
|
36
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
406
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
our $VERSION = '0.0504'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 INHERITANCE |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 2 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item * |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
extends L |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=back |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Extend Exception::Base class |
54
|
|
|
|
|
|
|
BEGIN { |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 CONSTANTS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=over |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item ATTRS : HashRef |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Declaration of class attributes as reference to hash. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
See L for details. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=back |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This class provides new attributes. See L for other |
72
|
|
|
|
|
|
|
descriptions. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
4
|
|
190
|
my %ATTRS = (); |
79
|
4
|
|
|
|
|
8
|
my @ATTRS_RW = (); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item reason : Str |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Contains the additional message filled by assertion method. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
4
|
|
|
|
|
10
|
push @ATTRS_RW, 'reason'; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item message : Str = "Unknown assertion failed" |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Contains the message of the exception. This class overrides the default value |
94
|
|
|
|
|
|
|
from L class. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
|
|
42
|
$ATTRS{message} = 'Unknown assertion failed'; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item verbosity : Int = 3 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The default verbosity for assertion exception is raised to 3. This class |
104
|
|
|
|
|
|
|
overrides the default value from L class. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
4
|
|
|
|
|
11
|
$ATTRS{verbosity} = 3; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item string_attributes : ArrayRef[Str] = ["message", "reason"] |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Meta-attribute contains the format of string representation of exception |
114
|
|
|
|
|
|
|
object. This class overrides the default value from L |
115
|
|
|
|
|
|
|
class. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
4
|
|
|
|
|
12
|
$ATTRS{string_attributes} = [ 'message', 'reason' ]; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
4
|
|
|
4
|
|
20
|
use Exception::Base 0.21; |
|
4
|
|
|
|
|
70
|
|
|
4
|
|
|
|
|
33
|
|
125
|
4
|
|
|
|
|
48
|
Exception::Base->import( |
126
|
|
|
|
|
|
|
'Exception::Assertion' => { |
127
|
|
|
|
|
|
|
has => { rw => \@ATTRS_RW }, |
128
|
|
|
|
|
|
|
%ATTRS, |
129
|
|
|
|
|
|
|
}, |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
}; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=begin umlwiki |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
= Class Diagram = |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
[ <> |
142
|
|
|
|
|
|
|
Exception::Assertion |
143
|
|
|
|
|
|
|
---------------------------------------------------------- |
144
|
|
|
|
|
|
|
+message : Str = "Unknown assertion failed" |
145
|
|
|
|
|
|
|
+verbosity : Int = 3 |
146
|
|
|
|
|
|
|
+reason : Str {rw} |
147
|
|
|
|
|
|
|
#string_attributes : ArrayRef[Str] = ["message", "reason"] |
148
|
|
|
|
|
|
|
----------------------------------------------------------] |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
[Exception::Assertion] ---|> [Exception::Base] |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=end umlwiki |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SEE ALSO |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L, L. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHOR |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Piotr Roszatycki |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 COPYRIGHT |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright (C) 2008, 2009 by Piotr Roszatycki . |
165
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
166
|
|
|
|
|
|
|
under the same terms as Perl itself. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
See L |