line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Aspect::Guard; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Aspect::Guard - General purpose guard object for destroy-time actions |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
SCOPE: { |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $guard = Aspect::Guard->new( sub { |
14
|
|
|
|
|
|
|
print "Goodbye World!\n"; |
15
|
|
|
|
|
|
|
} ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
# Prints here as it exits the scope |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
The B class shipping with L is a convenience module for |
23
|
|
|
|
|
|
|
creating C based objects that execute when they fall out of scope. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
It's usage is effectively summarised by the synopsis. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
21
|
|
|
21
|
|
81
|
use strict; |
|
21
|
|
|
|
|
26
|
|
|
21
|
|
|
|
|
573
|
|
32
|
21
|
|
|
21
|
|
85
|
use warnings; |
|
21
|
|
|
|
|
31
|
|
|
21
|
|
|
|
|
1849
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our $VERSION = '0.97_06'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=pod |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 new |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $guard = Aspect::Guard->new( sub { do_something(); } ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The C method creates a new guard object. It takes a single C |
43
|
|
|
|
|
|
|
references as a parameter, which it will bless into the guard class, which will |
44
|
|
|
|
|
|
|
execute the code reference when it's C hook is called. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
4
|
|
|
4
|
1
|
12
|
bless $_[1], $_[0]; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub DESTROY { |
53
|
4
|
|
|
4
|
|
11
|
$_[0]->(); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=pod |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 AUTHOR |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Adam Kennedy Eadamk@cpan.orgE |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 COPYRIGHT |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Copyright 2011 Adam Kennedy. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
69
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |