File Coverage

blib/lib/Aspect/Guard.pm
Criterion Covered Total %
statement 5 5 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 9 9 100.0


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 26     26   155 use strict;
  26         128  
  26         2925  
32              
33             our $VERSION = '1.04';
34              
35             =pod
36              
37             =head2 new
38              
39             my $guard = Aspect::Guard->new( sub { do_something(); } );
40              
41             The C method creates a new guard object. It takes a single C
42             references as a parameter, which it will bless into the guard class, which will
43             execute the code reference when it's C hook is called.
44              
45             =cut
46              
47             sub new {
48 4     4 1 20 bless $_[1], $_[0];
49             }
50              
51             sub DESTROY {
52 4     4   27 $_[0]->();
53             }
54              
55             1;
56              
57             =pod
58              
59             =head1 AUTHOR
60              
61             Adam Kennedy Eadamk@cpan.orgE
62              
63             =head1 COPYRIGHT
64              
65             Copyright 2011 - 2013 Adam Kennedy.
66              
67             This library is free software; you can redistribute it and/or modify
68             it under the same terms as Perl itself.
69              
70             =cut