Filename | /usr/local/lib/perl5/site_perl/mach/5.24/Razor2/Errorhandler.pm |
Statements | Executed 7 statements in 707µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 47µs | 55µs | BEGIN@13 | Razor2::Errorhandler::
1 | 1 | 1 | 21µs | 36µs | BEGIN@21 | Razor2::Errorhandler::
1 | 1 | 1 | 20µs | 26µs | BEGIN@32 | Razor2::Errorhandler::
0 | 0 | 0 | 0s | 0s | error | Razor2::Errorhandler::
0 | 0 | 0 | 0s | 0s | errprefix | Razor2::Errorhandler::
0 | 0 | 0 | 0s | 0s | errstr | Razor2::Errorhandler::
0 | 0 | 0 | 0s | 0s | errstrrst | Razor2::Errorhandler::
0 | 0 | 0 | 0s | 0s | new | Razor2::Errorhandler::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | #!/usr/local/bin/perl -sw | ||||
2 | ## | ||||
3 | ## Razor2::Errorhandler -- Base class that provides error | ||||
4 | ## handling functionality. | ||||
5 | ## | ||||
6 | ## Copyright (c) 2001, Vipul Ved Prakash. All rights reserved. | ||||
7 | ## This code is free software; you can redistribute it and/or modify | ||||
8 | ## it under the same terms as Perl itself. | ||||
9 | ## | ||||
10 | ## $Id: Errorhandler.pm,v 1.5 2005/08/03 21:43:09 rsoderberg Exp $ | ||||
11 | |||||
12 | package Razor2::Errorhandler; | ||||
13 | 2 | 130µs | 2 | 63µs | # spent 55µs (47+8) within Razor2::Errorhandler::BEGIN@13 which was called:
# once (47µs+8µs) by base::import at line 13 # spent 55µs making 1 call to Razor2::Errorhandler::BEGIN@13
# spent 8µs making 1 call to strict::import |
14 | |||||
15 | sub new { | ||||
16 | bless {}, shift | ||||
17 | } | ||||
18 | |||||
19 | |||||
20 | sub error { | ||||
21 | 2 | 219µs | 2 | 51µs | # spent 36µs (21+15) within Razor2::Errorhandler::BEGIN@21 which was called:
# once (21µs+15µs) by base::import at line 21 # spent 36µs making 1 call to Razor2::Errorhandler::BEGIN@21
# spent 15µs making 1 call to strict::unimport |
22 | my ($self, $errstr, $construction_error) = @_; | ||||
23 | if ($construction_error) { | ||||
24 | my ($package, @undef) = caller(); | ||||
25 | my $location = "$package\::errstr"; | ||||
26 | my $spot = *{$location}{SCALAR}; | ||||
27 | $$spot = "$errstr\n"; | ||||
28 | } else { | ||||
29 | $$self{errstr} = "$errstr\n"; | ||||
30 | } | ||||
31 | $self->log($self->{logerrors},"Error: $errstr\n") if $self->{logerrors}; | ||||
32 | 2 | 352µs | 2 | 32µs | # spent 26µs (20+6) within Razor2::Errorhandler::BEGIN@32 which was called:
# once (20µs+6µs) by base::import at line 32 # spent 26µs making 1 call to Razor2::Errorhandler::BEGIN@32
# spent 6µs making 1 call to strict::import |
33 | return; | ||||
34 | } | ||||
35 | |||||
36 | |||||
37 | sub errstr { | ||||
38 | my $self = shift; | ||||
39 | return $$self{errstr}; | ||||
40 | } | ||||
41 | |||||
42 | sub errprefix { | ||||
43 | my ($self, $prefix) = @_; | ||||
44 | $$self{errstr} = $prefix .": ". $$self{errstr}; | ||||
45 | return; | ||||
46 | } | ||||
47 | |||||
48 | sub errstrrst { | ||||
49 | my $self = shift; | ||||
50 | $$self{errstr} = ""; | ||||
51 | } | ||||
52 | |||||
53 | 1 | 6µs | 1; | ||
54 | |||||
55 | |||||
56 | =head1 NAME | ||||
57 | |||||
58 | Razor::Errorhandler - Error handling mechanism for Razor. | ||||
59 | |||||
60 | =head1 SYNOPSIS | ||||
61 | |||||
62 | package Foo; | ||||
63 | |||||
64 | use Razor::Errorhandler; | ||||
65 | @ISA = qw(Razor::Errorhandler); | ||||
66 | |||||
67 | sub alive { | ||||
68 | .. | ||||
69 | .. | ||||
70 | return | ||||
71 | $self->error ("Awake, awake! Ring the alarum bell. \ | ||||
72 | Murther and treason!", $dagger) | ||||
73 | if $self->murdered($king); | ||||
74 | } | ||||
75 | |||||
76 | |||||
77 | package main; | ||||
78 | |||||
79 | use Foo; | ||||
80 | my $foo = new Foo; | ||||
81 | $foo->alive($king) or print $foo->errstr(); | ||||
82 | # prints "Awake, awake! ... " | ||||
83 | |||||
84 | =head1 DESCRIPTION | ||||
85 | |||||
86 | Razor::Errorhandler encapsulates the error handling mechanism used by the | ||||
87 | modules in Razor bundle. Razor::Errorhandler doesn't have a constructor | ||||
88 | and is meant to be inherited. The derived modules use its two methods, | ||||
89 | error() and errstr(), to communicate error messages to the caller. | ||||
90 | |||||
91 | When a method of the derived module fails, it calls $self->error() and | ||||
92 | returns to the caller. The error message passed to error() is made | ||||
93 | available to the caller through the errstr() accessor. error() also | ||||
94 | accepts a list of sensitive data that it wipes out (undef'es) before | ||||
95 | returning. | ||||
96 | |||||
97 | The caller should B<never> call errstr() to check for errors. errstr() | ||||
98 | should be called only when a method indicates (usually through an undef | ||||
99 | return value) that an error has occured. This is because errstr() is | ||||
100 | never overwritten and will always contain a value after the occurance of | ||||
101 | first error. | ||||
102 | |||||
103 | =head1 METHODS | ||||
104 | |||||
105 | =over 4 | ||||
106 | |||||
107 | =item B<error($mesage, ($wipeme, $wipemetoo))> | ||||
108 | |||||
109 | The first argument to error() is $message which is placed in | ||||
110 | $self->{errstr} and the remaining arguments are interpretted as variables | ||||
111 | containing sensitive data that are wiped out from the memory. error() | ||||
112 | always returns undef. | ||||
113 | |||||
114 | =item B<errstr()> | ||||
115 | |||||
116 | errstr() is an accessor method for $self->{errstr}. | ||||
117 | |||||
118 | =back | ||||
119 | |||||
120 | =head1 AUTHOR | ||||
121 | |||||
122 | Vipul Ved Prakash, E<lt>mail@vipul.netE<gt> | ||||
123 | |||||
124 | =head1 SEE ALSO | ||||
125 | |||||
126 | Razor::Client(3) | ||||
127 | |||||
128 | =cut | ||||
129 | |||||
130 |