X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FGuard.pm;fp=lib%2FCPANPLUS%2FDist%2FGentoo%2FGuard.pm;h=87dbaa8361f3d861fb2e6a1c44825caf4103b0d2;hb=937bf27968e203fe3b6ea35150dbaee8f6b64458;hp=0000000000000000000000000000000000000000;hpb=ac86d926fe1f232054032ab4f36c301b8e5eccaa;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git diff --git a/lib/CPANPLUS/Dist/Gentoo/Guard.pm b/lib/CPANPLUS/Dist/Gentoo/Guard.pm new file mode 100644 index 0000000..87dbaa8 --- /dev/null +++ b/lib/CPANPLUS/Dist/Gentoo/Guard.pm @@ -0,0 +1,92 @@ +package CPANPLUS::Dist::Gentoo::Guard; + +use strict; +use warnings; + +=head1 NAME + +CPANPLUS::Dist::Gentoo::Guard - Scope guard object. + +=head1 VERSION + +Version 0.09 + +=cut + +our $VERSION = '0.09'; + +=head1 DESCRIPTION + +This is a scope guard object helper for L. + +=head1 METHODS + +=head2 C + +Creates a new L object that will call C<$coderef> when destroyed. + +=cut + +sub new { + my ($class, $code) = @_; + $class = ref($class) || $class; + + bless { + code => $code, + armed => 1, + }, $class; +} + +=head2 C + +Tells the object not to call the stored callback on destruction. + +=cut + +sub unarm { $_[0]->{armed} = 0 } + +=head2 C + +Calls the stored callback if the guard object is still armed. + +=cut + +sub DESTROY { + my ($self) = @_; + + $self->{code}->() if $self->{armed}; + $self->unarm; + + return; +} + +=head1 SEE ALSO + +L. + +=head1 AUTHOR + +Vincent Pit, C<< >>, L. + +You can contact me by mail or on C (vincent). + +=head1 BUGS + +Please report any bugs or feature requests to C, or through the web interface at L. +I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc CPANPLUS::Dist::Gentoo + +=head1 COPYRIGHT & LICENSE + +Copyright 2009,2010 Vincent Pit, all rights reserved. + +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. + +=cut + +1; # End of CPANPLUS::Dist::Gentoo::Guard