| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package autodie::Scope::Guard; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 59 |  |  | 59 |  | 264 | use strict; | 
|  | 59 |  |  |  |  | 79 |  | 
|  | 59 |  |  |  |  | 2451 |  | 
| 4 | 59 |  |  | 59 |  | 304 | use warnings; | 
|  | 59 |  |  |  |  | 69 |  | 
|  | 59 |  |  |  |  | 5532 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | # ABSTRACT: Wrapper class for calling subs at end of scope | 
| 7 |  |  |  |  |  |  | our $VERSION = '2.29'; # VERSION | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | # This code schedules the cleanup of subroutines at the end of | 
| 10 |  |  |  |  |  |  | # scope.  It's directly inspired by chocolateboy's excellent | 
| 11 |  |  |  |  |  |  | # Scope::Guard module. | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub new { | 
| 14 | 138 |  |  | 138 | 1 | 222 | my ($class, $handler) = @_; | 
| 15 | 138 |  |  |  |  | 981 | return bless($handler, $class); | 
| 16 |  |  |  |  |  |  | } | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | sub DESTROY { | 
| 19 | 133 |  |  | 133 |  | 70689 | my ($self) = @_; | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 133 |  |  |  |  | 397 | $self->(); | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | 1; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | __END__ | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =head1 NAME | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | autodie::Scope::Guard - Wrapper class for calling subs at end of scope | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | use autodie::Scope::Guard; | 
| 35 |  |  |  |  |  |  | $^H{'my-key'} = autodie::Scope::Guard->new(sub { | 
| 36 |  |  |  |  |  |  | print "Hallo world\n"; | 
| 37 |  |  |  |  |  |  | }); | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | This class is used to bless perl subs so that they are invoked when | 
| 42 |  |  |  |  |  |  | they are destroyed.  This is mostly useful for ensuring the code is | 
| 43 |  |  |  |  |  |  | invoked at end of scope.  This module is not a part of autodie's | 
| 44 |  |  |  |  |  |  | public API. | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | This module is directly inspired by chocolateboy's excellent | 
| 47 |  |  |  |  |  |  | Scope::Guard module. | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =head2 Methods | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =head3 new | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | my $hook = autodie::Scope::Guard->new(sub {}); | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | Creates a new C<autodie::Scope::Guard>, which will invoke the given | 
| 56 |  |  |  |  |  |  | sub once it goes out of scope (i.e. its DESTROY handler is called). | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =head1 AUTHOR | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | Copyright 2008-2009, Paul Fenwick E<lt>pjf@perltraining.com.auE<gt> | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =head1 LICENSE | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | This module is free software.  You may distribute it under the | 
| 65 |  |  |  |  |  |  | same terms as Perl itself. |