]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blob - lib/CPANPLUS/Dist/Gentoo/Guard.pm
2c4b582deaf9aa818c2a4c69cc5d4ea096e915f1
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo / Guard.pm
1 package CPANPLUS::Dist::Gentoo::Guard;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 CPANPLUS::Dist::Gentoo::Guard - Scope guard object.
9
10 =head1 VERSION
11
12 Version 0.11
13
14 =cut
15
16 our $VERSION = '0.11';
17
18 =head1 DESCRIPTION
19
20 This is a scope guard object helper for L<CPANPLUS::Dist::Gentoo>.
21
22 =head1 METHODS
23
24 =head2 C<new $coderef>
25
26 Creates a new L<CPANPLUS::Dist::Gentoo::Guard> object that will call C<$coderef> when destroyed.
27
28 =cut
29
30 sub new {
31  my ($class, $code) = @_;
32  $class = ref($class) || $class;
33
34  bless {
35   code  => $code,
36   armed => 1,
37  }, $class;
38 }
39
40 =head2 C<unarm>
41
42 Tells the object not to call the stored callback on destruction.
43
44 =cut
45
46 sub unarm { $_[0]->{armed} = 0 }
47
48 =head2 C<DESTROY>
49
50 Calls the stored callback if the guard object is still armed.
51
52 =cut
53
54 sub DESTROY {
55  my ($self) = @_;
56
57  $self->{code}->() if $self->{armed};
58  $self->unarm;
59
60  return;
61 }
62
63 =head1 SEE ALSO
64
65 L<CPANPLUS::Dist::Gentoo>.
66
67 =head1 AUTHOR
68
69 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
70
71 You can contact me by mail or on C<irc.perl.org> (vincent).
72
73 =head1 BUGS
74
75 Please report any bugs or feature requests to C<bug-cpanplus-dist-gentoo at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPANPLUS-Dist-Gentoo>.
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