File Coverage

blib/lib/CPANPLUS/Dist/Gentoo/Guard.pm
Criterion Covered Total %
statement 14 14 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 2 2 100.0
total 24 26 92.3


line stmt bran cond sub pod time code
1             package CPANPLUS::Dist::Gentoo::Guard;
2              
3 2     2   20365 use strict;
  2         4  
  2         67  
4 2     2   11 use warnings;
  2         2  
  2         297  
5              
6             =head1 NAME
7              
8             CPANPLUS::Dist::Gentoo::Guard - Scope guard object.
9              
10             =head1 VERSION
11              
12             Version 0.12
13              
14             =cut
15              
16             our $VERSION = '0.12';
17              
18             =head1 DESCRIPTION
19              
20             This is a scope guard object helper for L.
21              
22             =head1 METHODS
23              
24             =head2 C
25              
26             Creates a new L object that will call C<$coderef> when destroyed.
27              
28             =cut
29              
30             sub new {
31 3     3 1 3062 my ($class, $code) = @_;
32 3   33     18 $class = ref($class) || $class;
33              
34 3         24 bless {
35             code => $code,
36             armed => 1,
37             }, $class;
38             }
39              
40             =head2 C
41              
42             Tells the object not to call the stored callback on destruction.
43              
44             =cut
45              
46 5     5 1 11 sub unarm { $_[0]->{armed} = 0 }
47              
48             =head2 C
49              
50             Calls the stored callback if the guard object is still armed.
51              
52             =cut
53              
54             sub DESTROY {
55 4     4   1552 my ($self) = @_;
56              
57 4 100       22 $self->{code}->() if $self->{armed};
58 4         15 $self->unarm;
59              
60 4         13 return;
61             }
62              
63             =head1 SEE ALSO
64              
65             L.
66              
67             =head1 AUTHOR
68              
69             Vincent Pit, C<< >>, L.
70              
71             You can contact me by mail or on C (vincent).
72              
73             =head1 BUGS
74              
75             Please report any bugs or feature requests to C, or through the web interface at L.
76             I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
77              
78             =head1 SUPPORT
79              
80             You can find documentation for this module with the perldoc command.
81              
82             perldoc CPANPLUS::Dist::Gentoo
83              
84             =head1 COPYRIGHT & LICENSE
85              
86             Copyright 2009,2010,2011,2012 Vincent Pit, all rights reserved.
87              
88             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
89              
90             =cut
91              
92             1; # End of CPANPLUS::Dist::Gentoo::Guard