| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Scope/Guard.pm |
| Statements | Executed 16 statements in 1.18ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 69µs | 87µs | Scope::Guard::BEGIN@3 |
| 1 | 1 | 1 | 37µs | 196µs | Scope::Guard::BEGIN@6 |
| 1 | 1 | 1 | 37µs | 103µs | Scope::Guard::BEGIN@4 |
| 1 | 1 | 1 | 20µs | 20µs | Scope::Guard::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Scope::Guard::DESTROY |
| 0 | 0 | 0 | 0s | 0s | Scope::Guard::dismiss |
| 0 | 0 | 0 | 0s | 0s | Scope::Guard::guard |
| 0 | 0 | 0 | 0s | 0s | Scope::Guard::new |
| 0 | 0 | 0 | 0s | 0s | Scope::Guard::scope_guard |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Scope::Guard; | ||||
| 2 | |||||
| 3 | 3 | 95µs | 2 | 105µs | # spent 87µs (69+18) within Scope::Guard::BEGIN@3 which was called:
# once (69µs+18µs) by KiokuDB::Collapser::BEGIN@8 at line 3 # spent 87µs making 1 call to Scope::Guard::BEGIN@3
# spent 18µs making 1 call to strict::import |
| 4 | 3 | 113µs | 2 | 169µs | # spent 103µs (37+66) within Scope::Guard::BEGIN@4 which was called:
# once (37µs+66µs) by KiokuDB::Collapser::BEGIN@8 at line 4 # spent 103µs making 1 call to Scope::Guard::BEGIN@4
# spent 66µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 3 | 96µs | 2 | 355µs | # spent 196µs (37+159) within Scope::Guard::BEGIN@6 which was called:
# once (37µs+159µs) by KiokuDB::Collapser::BEGIN@8 at line 6 # spent 196µs making 1 call to Scope::Guard::BEGIN@6
# spent 159µs making 1 call to Exporter::import |
| 7 | 3 | 825µs | 1 | 20µs | # spent 20µs within Scope::Guard::BEGIN@7 which was called:
# once (20µs+0s) by KiokuDB::Collapser::BEGIN@8 at line 7 # spent 20µs making 1 call to Scope::Guard::BEGIN@7 |
| 8 | |||||
| 9 | 1 | 31µs | our @ISA = qw(Exporter); | ||
| 10 | 1 | 4µs | our @EXPORT_OK = qw(guard scope_guard); | ||
| 11 | 1 | 3µs | our $VERSION = '0.20'; | ||
| 12 | |||||
| 13 | sub new { | ||||
| 14 | confess "Can't create a Scope::Guard in void context" unless (defined wantarray); | ||||
| 15 | |||||
| 16 | my $class = shift; | ||||
| 17 | my $handler = shift() || die 'Scope::Guard::new: no handler supplied'; | ||||
| 18 | my $ref = ref $handler || ''; | ||||
| 19 | |||||
| 20 | die "Scope::Guard::new: invalid handler - expected CODE ref, got: '$ref'" | ||||
| 21 | unless (UNIVERSAL::isa($handler, 'CODE')); | ||||
| 22 | |||||
| 23 | bless [ 0, $handler ], ref $class || $class; | ||||
| 24 | } | ||||
| 25 | |||||
| 26 | sub dismiss { | ||||
| 27 | my $self = shift; | ||||
| 28 | my $dismiss = @_ ? shift : 1; | ||||
| 29 | |||||
| 30 | $self->[0] = $dismiss; | ||||
| 31 | } | ||||
| 32 | |||||
| 33 | sub guard(&) { __PACKAGE__->new(shift) } | ||||
| 34 | sub scope_guard($) { __PACKAGE__->new(shift) } | ||||
| 35 | |||||
| 36 | sub DESTROY { | ||||
| 37 | my $self = shift; | ||||
| 38 | my ($dismiss, $handler) = @$self; | ||||
| 39 | |||||
| 40 | $handler->() unless ($dismiss); | ||||
| 41 | } | ||||
| 42 | |||||
| 43 | 1 | 15µs | 1; | ||
| 44 | |||||
| 45 | __END__ |