Filename | /usr/lib/x86_64-linux-gnu/perl5/5.20/Template/Exception.pm |
Statements | Executed 14 statements in 846µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 26µs | 90µs | BEGIN@27 | Template::Exception::
1 | 1 | 1 | 13µs | 20µs | BEGIN@22 | Template::Exception::
1 | 1 | 1 | 10µs | 41µs | BEGIN@24 | Template::Exception::
1 | 1 | 1 | 7µs | 22µs | BEGIN@25 | Template::Exception::
1 | 1 | 1 | 7µs | 23µs | BEGIN@26 | Template::Exception::
1 | 1 | 1 | 7µs | 11µs | BEGIN@23 | Template::Exception::
0 | 0 | 0 | 0s | 0s | as_string | Template::Exception::
0 | 0 | 0 | 0s | 0s | info | Template::Exception::
0 | 0 | 0 | 0s | 0s | new | Template::Exception::
0 | 0 | 0 | 0s | 0s | select_handler | Template::Exception::
0 | 0 | 0 | 0s | 0s | text | Template::Exception::
0 | 0 | 0 | 0s | 0s | type | Template::Exception::
0 | 0 | 0 | 0s | 0s | type_info | Template::Exception::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | #============================================================= -*-Perl-*- | ||||
2 | # | ||||
3 | # Template::Exception | ||||
4 | # | ||||
5 | # DESCRIPTION | ||||
6 | # Module implementing a generic exception class used for error handling | ||||
7 | # in the Template Toolkit. | ||||
8 | # | ||||
9 | # AUTHOR | ||||
10 | # Andy Wardley <abw@wardley.org> | ||||
11 | # | ||||
12 | # COPYRIGHT | ||||
13 | # Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. | ||||
14 | # | ||||
15 | # This module is free software; you can redistribute it and/or | ||||
16 | # modify it under the same terms as Perl itself. | ||||
17 | # | ||||
18 | #======================================================================== | ||||
19 | |||||
20 | package Template::Exception; | ||||
21 | |||||
22 | 2 | 37µs | 2 | 27µs | # spent 20µs (13+7) within Template::Exception::BEGIN@22 which was called:
# once (13µs+7µs) by Template::Service::BEGIN@27 at line 22 # spent 20µs making 1 call to Template::Exception::BEGIN@22
# spent 7µs making 1 call to strict::import |
23 | 2 | 30µs | 2 | 16µs | # spent 11µs (7+5) within Template::Exception::BEGIN@23 which was called:
# once (7µs+5µs) by Template::Service::BEGIN@27 at line 23 # spent 11µs making 1 call to Template::Exception::BEGIN@23
# spent 5µs making 1 call to warnings::import |
24 | 2 | 67µs | 2 | 72µs | # spent 41µs (10+31) within Template::Exception::BEGIN@24 which was called:
# once (10µs+31µs) by Template::Service::BEGIN@27 at line 24 # spent 41µs making 1 call to Template::Exception::BEGIN@24
# spent 31µs making 1 call to constant::import |
25 | 2 | 42µs | 2 | 36µs | # spent 22µs (7+15) within Template::Exception::BEGIN@25 which was called:
# once (7µs+15µs) by Template::Service::BEGIN@27 at line 25 # spent 22µs making 1 call to Template::Exception::BEGIN@25
# spent 15µs making 1 call to constant::import |
26 | 2 | 47µs | 2 | 39µs | # spent 23µs (7+16) within Template::Exception::BEGIN@26 which was called:
# once (7µs+16µs) by Template::Service::BEGIN@27 at line 26 # spent 23µs making 1 call to Template::Exception::BEGIN@26
# spent 16µs making 1 call to constant::import |
27 | 2 | 621µs | 2 | 153µs | # spent 90µs (26+63) within Template::Exception::BEGIN@27 which was called:
# once (26µs+63µs) by Template::Service::BEGIN@27 at line 27 # spent 90µs making 1 call to Template::Exception::BEGIN@27
# spent 63µs making 1 call to overload::import |
28 | |||||
29 | 1 | 400ns | our $VERSION = 2.70; | ||
30 | |||||
31 | |||||
32 | #------------------------------------------------------------------------ | ||||
33 | # new($type, $info, \$text) | ||||
34 | # | ||||
35 | # Constructor method used to instantiate a new Template::Exception | ||||
36 | # object. The first parameter should contain the exception type. This | ||||
37 | # can be any arbitrary string of the caller's choice to represent a | ||||
38 | # specific exception. The second parameter should contain any | ||||
39 | # information (i.e. error message or data reference) relevant to the | ||||
40 | # specific exception event. The third optional parameter may be a | ||||
41 | # reference to a scalar containing output text from the template | ||||
42 | # block up to the point where the exception was thrown. | ||||
43 | #------------------------------------------------------------------------ | ||||
44 | |||||
45 | sub new { | ||||
46 | my ($class, $type, $info, $textref) = @_; | ||||
47 | bless [ $type, $info, $textref ], $class; | ||||
48 | } | ||||
49 | |||||
50 | |||||
51 | #------------------------------------------------------------------------ | ||||
52 | # type() | ||||
53 | # info() | ||||
54 | # type_info() | ||||
55 | # | ||||
56 | # Accessor methods to return the internal TYPE and INFO fields. | ||||
57 | #------------------------------------------------------------------------ | ||||
58 | |||||
59 | sub type { | ||||
60 | $_[0]->[ TYPE ]; | ||||
61 | } | ||||
62 | |||||
63 | sub info { | ||||
64 | $_[0]->[ INFO ]; | ||||
65 | } | ||||
66 | |||||
67 | sub type_info { | ||||
68 | my $self = shift; | ||||
69 | @$self[ TYPE, INFO ]; | ||||
70 | } | ||||
71 | |||||
72 | #------------------------------------------------------------------------ | ||||
73 | # text() | ||||
74 | # text(\$pretext) | ||||
75 | # | ||||
76 | # Method to return the text referenced by the TEXT member. A text | ||||
77 | # reference may be passed as a parameter to supercede the existing | ||||
78 | # member. The existing text is added to the *end* of the new text | ||||
79 | # before being stored. This facility is provided for template blocks | ||||
80 | # to gracefully de-nest when an exception occurs and allows them to | ||||
81 | # reconstruct their output in the correct order. | ||||
82 | #------------------------------------------------------------------------ | ||||
83 | |||||
84 | sub text { | ||||
85 | my ($self, $newtextref) = @_; | ||||
86 | my $textref = $self->[ TEXT ]; | ||||
87 | |||||
88 | if ($newtextref) { | ||||
89 | $$newtextref .= $$textref if $textref && $textref ne $newtextref; | ||||
90 | $self->[ TEXT ] = $newtextref; | ||||
91 | return ''; | ||||
92 | } | ||||
93 | elsif ($textref) { | ||||
94 | return $$textref; | ||||
95 | } | ||||
96 | else { | ||||
97 | return ''; | ||||
98 | } | ||||
99 | } | ||||
100 | |||||
101 | |||||
102 | #------------------------------------------------------------------------ | ||||
103 | # as_string() | ||||
104 | # | ||||
105 | # Accessor method to return a string indicating the exception type and | ||||
106 | # information. | ||||
107 | #------------------------------------------------------------------------ | ||||
108 | |||||
109 | sub as_string { | ||||
110 | my $self = shift; | ||||
111 | return $self->[ TYPE ] . ' error - ' . $self->[ INFO ]; | ||||
112 | } | ||||
113 | |||||
114 | |||||
115 | #------------------------------------------------------------------------ | ||||
116 | # select_handler(@types) | ||||
117 | # | ||||
118 | # Selects the most appropriate handler for the exception TYPE, from | ||||
119 | # the list of types passed in as parameters. The method returns the | ||||
120 | # item which is an exact match for TYPE or the closest, more | ||||
121 | # generic handler (e.g. foo being more generic than foo.bar, etc.) | ||||
122 | #------------------------------------------------------------------------ | ||||
123 | |||||
124 | sub select_handler { | ||||
125 | my ($self, @options) = @_; | ||||
126 | my $type = $self->[ TYPE ]; | ||||
127 | my %hlut; | ||||
128 | @hlut{ @options } = (1) x @options; | ||||
129 | |||||
130 | while ($type) { | ||||
131 | return $type if $hlut{ $type }; | ||||
132 | |||||
133 | # strip .element from the end of the exception type to find a | ||||
134 | # more generic handler | ||||
135 | $type =~ s/\.?[^\.]*$//; | ||||
136 | } | ||||
137 | return undef; | ||||
138 | } | ||||
139 | |||||
140 | 1 | 3µs | 1; | ||
141 | |||||
142 | __END__ |