diff options
author | Karl Berry <karl@freefriends.org> | 2016-04-05 22:27:26 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-04-05 22:27:26 +0000 |
commit | b56b320b5e2515160073fa1b469514002688fe11 (patch) | |
tree | 965a7100c5e45fca8ec803d22b8b6ce14fca4633 /Master/tlpkg/tlperl/lib/autodie/Scope/Guard.pm | |
parent | d26c206452d2e285c3bbf949f34011e4a55fd8f9 (diff) |
tlperl 5.22.1 from siep
git-svn-id: svn://tug.org/texlive/trunk@40252 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/autodie/Scope/Guard.pm')
-rw-r--r-- | Master/tlpkg/tlperl/lib/autodie/Scope/Guard.pm | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Master/tlpkg/tlperl/lib/autodie/Scope/Guard.pm b/Master/tlpkg/tlperl/lib/autodie/Scope/Guard.pm new file mode 100644 index 00000000000..db38e36facd --- /dev/null +++ b/Master/tlpkg/tlperl/lib/autodie/Scope/Guard.pm @@ -0,0 +1,65 @@ +package autodie::Scope::Guard; + +use strict; +use warnings; + +# ABSTRACT: Wrapper class for calling subs at end of scope +our $VERSION = '2.26'; # VERSION + +# This code schedules the cleanup of subroutines at the end of +# scope. It's directly inspired by chocolateboy's excellent +# Scope::Guard module. + +sub new { + my ($class, $handler) = @_; + return bless($handler, $class); +} + +sub DESTROY { + my ($self) = @_; + + $self->(); +} + +1; + +__END__ + +=head1 NAME + +autodie::Scope::Guard - Wrapper class for calling subs at end of scope + +=head1 SYNOPSIS + + use autodie::Scope::Guard; + $^H{'my-key'} = autodie::Scope::Guard->new(sub { + print "Hallo world\n"; + }); + +=head1 DESCRIPTION + +This class is used to bless perl subs so that they are invoked when +they are destroyed. This is mostly useful for ensuring the code is +invoked at end of scope. This module is not a part of autodie's +public API. + +This module is directly inspired by chocolateboy's excellent +Scope::Guard module. + +=head2 Methods + +=head3 new + + my $hook = autodie::Scope::Guard->new(sub {}); + +Creates a new C<autodie::Scope::Guard>, which will invoke the given +sub once it goes out of scope (i.e. its DESTROY handler is called). + +=head1 AUTHOR + +Copyright 2008-2009, Paul Fenwick E<lt>pjf@perltraining.com.auE<gt> + +=head1 LICENSE + +This module is free software. You may distribute it under the +same terms as Perl itself. |