]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blob - lib/CPANPLUS/Dist/Gentoo/Guard.pm
Make sure the POD headings are linkable
[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.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<CPANPLUS::Dist::Gentoo>.
21
22 =head1 METHODS
23
24 =head2 C<new>
25
26     my $guard = CPANPLUS::Dist::Gentoo::Guard->new($coderef);
27
28 Creates a new L<CPANPLUS::Dist::Gentoo::Guard> object that will call C<$coderef> when destroyed.
29
30 =cut
31
32 sub new {
33  my ($class, $code) = @_;
34  $class = ref($class) || $class;
35
36  bless {
37   code  => $code,
38   armed => 1,
39  }, $class;
40 }
41
42 =head2 C<unarm>
43
44 Tells the object not to call the stored callback on destruction.
45
46 =cut
47
48 sub unarm { $_[0]->{armed} = 0 }
49
50 =head2 C<DESTROY>
51
52 Calls the stored callback if the guard object is still armed.
53
54 =cut
55
56 sub DESTROY {
57  my ($self) = @_;
58
59  $self->{code}->() if $self->{armed};
60  $self->unarm;
61
62  return;
63 }
64
65 =head1 SEE ALSO
66
67 L<CPANPLUS::Dist::Gentoo>.
68
69 =head1 AUTHOR
70
71 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
72
73 You can contact me by mail or on C<irc.perl.org> (vincent).
74
75 =head1 BUGS
76
77 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>.
78 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
79
80 =head1 SUPPORT
81
82 You can find documentation for this module with the perldoc command.
83
84     perldoc CPANPLUS::Dist::Gentoo
85
86 =head1 COPYRIGHT & LICENSE
87
88 Copyright 2009,2010,2011,2012 Vincent Pit, all rights reserved.
89
90 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
91
92 =cut
93
94 1; # End of CPANPLUS::Dist::Gentoo::Guard