Aspect/Guard.pm

filter: Statementstmt 100% 10 / 10 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 15 / 15 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
new
1.0
CRAP 1.0
« Aspect/Library/Wormhole.pm ↑ Summary Aspect/Hook.pm »
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<Aspect::Guard> class shipping with L<Aspect> is a convenience module for
23 creating C<CODE> 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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 21 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<new> method creates a new guard object. It takes a single C<CODE>
43 references as a parameter, which it will bless into the guard class, which will
44 execute the code reference when it's C<DESTROY> hook is called.
45  
46 =cut
47  
48 sub new {
49 4 ▶ bless $_[1], $_[0];
Subroutine new: called CC=1 SCAR=0.0
Pod documented
50 }
51  
52 sub DESTROY {
53 4 ▶ $_[0]->();
Subroutine DESTROY: called CC=1 SCAR=0.0
54 }
55  
56 21 1;
57  
58 =pod
59  
60 =head1 AUTHOR
61  
62 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
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
« Aspect/Library/Wormhole.pm ↑ Summary Aspect/Hook.pm »