End-2009110401/0000755000076400007640000000000011274320225012373 5ustar abigailabigailEnd-2009110401/Makefile.PL0000644000076400007640000000230111274317367014356 0ustar abigailabigail#!/usr/bin/perl use 5.006; use strict; use warnings; no warnings 'syntax'; use ExtUtils::MakeMaker; my %args = ( NAME => 'End', VERSION_FROM => 'lib/End.pm', ABSTRACT_FROM => 'lib/End.pm', PREREQ_PM => {'strict' => 0, 'warnings' => 0, 'Exporter' => 0, }, MIN_PERL_VERSION => 5.006, AUTHOR => 'Abigail ', LICENSE => 'mit', META_MERGE => { build_requires => { }, test_requires => { }, resources => { repository => 'git://github.com/Abigail/end.git', }, keywords => [qw [ ]], }, ); my %filter = ( MIN_PERL_VERSION => '6.48', LICENSE => '6.48', META_MERGE => '6.46', AUTHOR => '6.07', ABSTRACT_FROM => '6.07', ); delete $args {$_} for grep {defined $filter {$_} && $ExtUtils::MakeMaker::VERSION lt $filter {$_}} keys %args; WriteMakefile %args; __END__ End-2009110401/MANIFEST0000644000076400007640000000027611274320225013531 0ustar abigailabigaillib/End.pm MANIFEST Makefile.PL t/000_tests.t t/950_pod.t t/960_pod_coverage.t t/990_kwalitee.t README Changes META.yml Module meta-data (added by MakeMaker) End-2009110401/Changes0000644000076400007640000000021611274317605013675 0ustar abigailabigailVersion 2009110401 + Modernized Makefile.PL + Added POD and Kwalitee tests Version 2009081101 + Created Changes. + Added README to MANIFEST. End-2009110401/t/0000755000076400007640000000000011274320224012635 5ustar abigailabigailEnd-2009110401/t/000_tests.t0000755000076400007640000000157011165204176014557 0ustar abigailabigail# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..3\n"; } END {print "not ok 1\n" unless $loaded;} use End; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): my $i = 1; { my $foo = end {$i ++}; $i += 2; last; $i += 2; } print $i == 4 ? "ok 2\n" : "not ok 2\n"; my $sum = 0; foreach my $i (1 .. 9) { my $foo = end {$sum += $i}; next; } print $sum == 45 ? "ok 3\n" : "not ok 3\n"; End-2009110401/t/950_pod.t0000755000076400007640000000031411274317474014217 0ustar abigailabigail#!/usr/bin/perl use Test::More; use strict; use warnings; no warnings 'syntax'; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod required for testing POD" if $@; all_pod_files_ok (); __END__ End-2009110401/t/990_kwalitee.t0000755000076400007640000000050011274317474015243 0ustar abigailabigail#!/usr/bin/perl use strict; use warnings; use Test::More; my $garbage = "Debian_CPANTS.txt"; eval { require Test::Kwalitee; Test::Kwalitee -> import; }; plan skip_all => 'Test::Kwalitee not installed; skipping' if $@; if (-f $garbage) { unlink $garbage or die "Failed to clean up $garbage"; } __END__ End-2009110401/t/960_pod_coverage.t0000755000076400007640000000037011274317474016075 0ustar abigailabigail#!/usr/bin/perl use Test::More; use strict; use warnings; no warnings 'syntax'; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage required for testing POD" if $@; all_pod_coverage_ok ({private => [qr /^/]}); __END__ End-2009110401/META.yml0000644000076400007640000000124211274320225013643 0ustar abigailabigail--- #YAML:1.0 name: End version: 2009110401 abstract: generalized END {}. author: - Abigail license: mit distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: Exporter: 0 perl: 5.006 strict: 0 warnings: 0 resources: repository: git://github.com/Abigail/end.git no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.55_02 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 keywords: [] test_requires: {} End-2009110401/lib/0000755000076400007640000000000011274320224013140 5ustar abigailabigailEnd-2009110401/lib/End.pm0000644000076400007640000000624011274317642014220 0ustar abigailabigailpackage End; use 5.006; use strict; use warnings; no warnings 'syntax'; use Exporter; our @ISA = qw /Exporter/; our @EXPORT = qw /end/; our $VERSION = '2009110401'; sub end (&) { my $code = shift; # Due to a bug in Perl 5.6.0, we can't just bless $code. # But by creating an extra closure, it'll work. bless sub {$code -> ()} => __PACKAGE__; } DESTROY {$_ [0] -> ()} 1; __END__ =pod =head1 NAME End - generalized END {}. =head1 SYNOPSIS use End; { my $foo = end {print "Leaving the block\n"}; ... last; # prints "Leaving the block\n". ... } =head1 DESCRIPTION The module C exports a single subroutine C, which allows you to set up some code that is run whenever the current block is exited, regardless whether that is due to a C, C, C, C, C, C, C or just reaching the end of the block. To be more precise, C returns an object, that will execute the code when the object is destroyed; that is, when the variable assigned to goes out of scope. If the variable is lexical to the current block, the code will be executed when leaving the block. One can force premature execution of the code by undefining the variable assigned to, or assigning another value to the variable. C only takes one argument, a code reference. If one wishes the code reference to take arguments, wrapping the code reference in a closure suffices. =head1 BUGS Due to a bug in Perl 5.6.0 (and perhaps before), anonymous subroutines that are not a closure will not go out of scope, not even on program termination. That is why C wraps the code fragment in a closure. There is a second bug in Perl 5.6.0 (and perhaps before) why this is necessary. If the code fragment isn't wrapped in another code reference, the original subroutine will be blessed in the package, making that C on that code no longer returns the right value. =head1 DEVELOPMENT The current sources of this module are found on github, L<< git://github.com/Abigail/end.git >>. =head1 AUTHOR This package was written by Abigail, L<< mailto:cpan@abigail.be >> =head1 COPYRIGHT & LICENSE Copyright (C) 2000 - 2009, Abigail Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =cut End-2009110401/README0000644000076400007640000000554011165205605013262 0ustar abigailabigailNAME End - generalized END {}. SYNOPSIS use End; { my $foo = end {print "Leaving the block\n"}; ... last; # prints "Leaving the block\n". ... } DESCRIPTION The module "End" exports a single subroutine "end", which allows you to set up some code that is run whenever the current block is exited, regardless whether that is due to a "return", "next", "last", "redo", "exit", "die", "goto" or just reaching the end of the block. To be more precise, "end" returns an object, that will execute the code when the object is destroyed; that is, when the variable assigned to goes out of scope. If the variable is lexical to the current block, the code will be executed when leaving the block. One can force premature execution of the code by undefining the variable assigned to, or assigning another value to the variable. "end" only takes one argument, a code reference. If one wishes the code reference to take arguments, wrapping the code reference in a closure suffices. BUGS Due to a bug in Perl 5.6.0 (and perhaps before), anonymous subroutines that are not a closure will not go out of scope, not even on program termination. That is why "end" wraps the code fragment in a closure. There is a second bug in Perl 5.6.0 (and perhaps before) why this is necessary. If the code fragment isn't wrapped in another code reference, the original subroutine will be blessed in the package, making that "ref" on that code no longer returns the right value. DEVELOPMENT The current sources of this module are found on github, . AUTHOR This package was written by Abigail, COPYRIGHT & LICENSE Copyright (C) 2000 - 2009, Abigail Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.