r54797 - in /branches/upstream/libscope-guard-perl/current: Changes MANIFEST META.yml Makefile.PL README lib/Scope/Guard.pm t/Scope-Guard.t t/guard.t t/new.t t/scope_guard.t
ansgar-guest at users.alioth.debian.org
ansgar-guest at users.alioth.debian.org
Fri Mar 26 05:13:33 UTC 2010
Author: ansgar-guest
Date: Fri Mar 26 05:13:26 2010
New Revision: 54797
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=54797
Log:
[svn-upgrade] Integrating new upstream version, libscope-guard-perl (0.11)
Added:
branches/upstream/libscope-guard-perl/current/t/guard.t
branches/upstream/libscope-guard-perl/current/t/new.t
branches/upstream/libscope-guard-perl/current/t/scope_guard.t
Removed:
branches/upstream/libscope-guard-perl/current/t/Scope-Guard.t
Modified:
branches/upstream/libscope-guard-perl/current/Changes
branches/upstream/libscope-guard-perl/current/MANIFEST
branches/upstream/libscope-guard-perl/current/META.yml
branches/upstream/libscope-guard-perl/current/Makefile.PL
branches/upstream/libscope-guard-perl/current/README
branches/upstream/libscope-guard-perl/current/lib/Scope/Guard.pm
Modified: branches/upstream/libscope-guard-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscope-guard-perl/current/Changes?rev=54797&op=diff
==============================================================================
--- branches/upstream/libscope-guard-perl/current/Changes (original)
+++ branches/upstream/libscope-guard-perl/current/Changes Fri Mar 26 05:13:26 2010
@@ -1,4 +1,10 @@
Revision history for Perl extension Scope::Guard.
+
+0.11 Thu Mar 25 22:08:05 2010
+ - doc tweak
+
+0.10 Thu Mar 25 20:14:25 2010
+ - add guard() and scope_guard() - thanks Tim Bunce
0.03 Sun Jan 7 19:19:17 2007
- POD fix (thanks Craig Manley)
Modified: branches/upstream/libscope-guard-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscope-guard-perl/current/MANIFEST?rev=54797&op=diff
==============================================================================
--- branches/upstream/libscope-guard-perl/current/MANIFEST (original)
+++ branches/upstream/libscope-guard-perl/current/MANIFEST Fri Mar 26 05:13:26 2010
@@ -1,9 +1,11 @@
Changes
-MANIFEST
+lib/Scope/Guard.pm
+Makefile.PL
+MANIFEST This list of files
META.yml
-Makefile.PL
README
-lib/Scope/Guard.pm
-t/Scope-Guard.t
+t/guard.t
+t/new.t
t/pod.t
t/pod_coverage.t
+t/scope_guard.t
Modified: branches/upstream/libscope-guard-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscope-guard-perl/current/META.yml?rev=54797&op=diff
==============================================================================
--- branches/upstream/libscope-guard-perl/current/META.yml (original)
+++ branches/upstream/libscope-guard-perl/current/META.yml Fri Mar 26 05:13:26 2010
@@ -1,11 +1,20 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
-name: Scope-Guard
-version: 0.03
-version_from: lib/Scope/Guard.pm
-installdirs: site
+--- #YAML:1.0
+name: Scope-Guard
+version: 0.11
+abstract: lexically scoped resource management
+author:
+ - chocolateboy <chocolate at cpan.org>
+license: unknown
+distribution_type: module
+configure_requires:
+ ExtUtils::MakeMaker: 0
requires:
- Test::More: 0
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.17
+ Test::More: 0
+no_index:
+ directory:
+ - t
+ - inc
+generated_by: ExtUtils::MakeMaker version 6.48
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
Modified: branches/upstream/libscope-guard-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscope-guard-perl/current/Makefile.PL?rev=54797&op=diff
==============================================================================
--- branches/upstream/libscope-guard-perl/current/Makefile.PL (original)
+++ branches/upstream/libscope-guard-perl/current/Makefile.PL Fri Mar 26 05:13:26 2010
@@ -1,14 +1,17 @@
use 5.006001;
+
+use strict;
+use warnings;
+
use ExtUtils::MakeMaker;
-# See lib/ExtUtils/MakeMaker.pm for details of how to influence
-# the contents of the Makefile that is written.
+
WriteMakefile(
NAME => 'Scope::Guard',
VERSION_FROM => 'lib/Scope/Guard.pm', # finds $VERSION
PREREQ_PM => {
- 'Test::More' => 0,
- }, # e.g., Module::Name => 1.1
+ 'Test::More' => 0,
+ },
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Scope/Guard.pm', # retrieve abstract from module
- AUTHOR => 'chocolateboy <chocolate.boy at email.com>') : ()),
+ AUTHOR => 'chocolateboy <chocolate at cpan.org>') : ()),
);
Modified: branches/upstream/libscope-guard-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscope-guard-perl/current/README?rev=54797&op=diff
==============================================================================
--- branches/upstream/libscope-guard-perl/current/README (original)
+++ branches/upstream/libscope-guard-perl/current/README Fri Mar 26 05:13:26 2010
@@ -1,4 +1,4 @@
-Scope-Guard version 0.03
+Scope-Guard version 0.11
========================
This module provides a convenient way to perform cleanup or other forms of resource
@@ -21,7 +21,7 @@
COPYRIGHT AND LICENCE
-Copyright (c) 2005-2007 by chocolateboy <chocolate.boy at email.com>
+Copyright (c) 2005-2010 by chocolateboy <chocolate at cpan.org>
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
Modified: branches/upstream/libscope-guard-perl/current/lib/Scope/Guard.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscope-guard-perl/current/lib/Scope/Guard.pm?rev=54797&op=diff
==============================================================================
--- branches/upstream/libscope-guard-perl/current/lib/Scope/Guard.pm (original)
+++ branches/upstream/libscope-guard-perl/current/lib/Scope/Guard.pm Fri Mar 26 05:13:26 2010
@@ -3,13 +3,15 @@
use strict;
use warnings;
-use vars qw($VERSION);
+use Exporter ();
-$VERSION = '0.03';
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw(guard scope_guard);
+our $VERSION = '0.11';
sub new {
my $class = shift;
- my $handler = shift() || die "Scope::Guard::new: no handler supplied";
+ my $handler = shift() || die 'Scope::Guard::new: no handler supplied';
my $ref = ref $handler || '';
die "Scope::Guard::new: invalid handler - expected CODE ref, got: '$ref'"
@@ -24,6 +26,9 @@
$self->[0] = $dismiss;
}
+
+sub guard(&) { __PACKAGE__->new(shift) }
+sub scope_guard($) { __PACKAGE__->new(shift) }
sub DESTROY {
my $self = shift;
@@ -44,84 +49,136 @@
=head1 SYNOPSIS
- my $sg = Scope::Guard->new(sub { ... });
+ my $guard = guard { ... };
- # or
+ # or
- my $sg = Scope::Guard->new(\&handler);
+ my $guard = scope_guard \&handler;
- $sg->dismiss(); # disable the handler
+ # or
+
+ my $guard = Scope::Guard->new(\&handler);
+
+ $guard->dismiss(); # disable the handler
=head1 DESCRIPTION
This module provides a convenient way to perform cleanup or other forms of resource
management at the end of a scope. It is particularly useful when dealing with exceptions:
-the Scope::Guard constructor takes a reference to a subroutine that is guaranteed to
+the C<Scope::Guard> constructor takes a reference to a subroutine that is guaranteed to
be called even if the thread of execution is aborted prematurely. This effectively allows
lexically-scoped "promises" to be made that are automatically honoured by perl's garbage
collector.
-For more information, see: L<http://www.cuj.com/documents/s=8000/cujcexp1812alexandr/>
+For more information, see: L<http://www.drdobbs.com/cpp/184403758>
+
+=head1 METHODS
=head2 new
-=head3 usage
+ my $guard = Scope::Guard->new(sub { ... });
- my $sg = Scope::Guard->new(sub { ... });
+ # or
- # or
+ my $guard = Scope::Guard->new(\&handler);
- my $sg = Scope::Guard->new(\&handler);
-
-=head3 description
-
-Create a new Scope::Guard object which calls the supplied handler when its C<DESTROY> method is
+The C<new> method creates a new C<Scope::Guard> object which calls the supplied handler when its C<DESTROY> method is
called, typically when it goes out of scope.
=head2 dismiss
-=head3 usage
+ $guard->dismiss();
- $sg->dismiss();
+ # or
- # or
+ $guard->dismiss(1);
- $sg->dismiss(1);
-
-=head3 description
-
-Detach the handler from the Scope::Guard object. This revokes the "promise" to call the
+C<dismiss> detaches the handler from the C<Scope::Guard> object. This revokes the "promise" to call the
handler when the object is destroyed.
The handler can be re-enabled by calling:
- $sg->dismiss(0);
+ $guard->dismiss(0);
+
+=head1 EXPORTS
+
+=head2 guard
+
+C<guard> takes a block and returns a new C<Scope::Guard> object. It can be used
+as a shorthand for:
+
+ Scope::Guard->new(...)
+
+e.g.
+
+ my $guard = guard { ... };
+
+- or it can be called in void context to create a guard for the current scope e.g.
+
+ guard { ... };
+
+Because there is no way to dismiss the guard in the latter case, it is assumed that
+the block knows how to deal with situations in which the resource has already been
+managed e.g.
+
+ guard {
+ unless ($resource->disposed) {
+ $resource->dispose;
+ }
+ };
+
+=head2 scope_guard
+
+C<scope_guard> is the same as C<guard>, but it takes a scalar (e.g. a code ref) rather than a block.
+e.g.
+
+ my $guard = scope_guard \&handler;
+
+or:
+
+ my $guard = scope_guard sub { ... };
+
+or:
+
+ my $guard = scope_guard $handler;
+
+Like C<guard>, it can be called in void context to install an anonymous guard in the current scope.
=head1 VERSION
-0.03
+0.11
=head1 SEE ALSO
=over
-=item * L<Hook::LexWrap|Hook::LexWrap>
+=item * L<B::Hooks::EndOfScope|B::Hooks::EndOfScope>
+
+=item * L<End|End>
+
+=item * L<Guard|Guard>
=item * L<Hook::Scope|Hook::Scope>
+=item * L<Object::Destroyer|Object::Destroyer>
+
+=item * L<Perl::AtEndOfScope|Perl::AtEndOfScope>
+
+=item * L<ReleaseAction|ReleaseAction>
+
+=item * L<Scope::OnExit|Scope::OnExit>
+
=item * L<Sub::ScopeFinalizer|Sub::ScopeFinalizer>
-
-=item * L<Object::Destroyer|Object::Destroyer>
=back
=head1 AUTHOR
-chocolateboy: <chocolate.boy at email.com>
+chocolateboy <chocolate at cpan.org>
=head1 COPYRIGHT
-Copyright (c) 2005-2007, chocolateboy.
+Copyright (c) 2005-2010, chocolateboy.
This module is free software. It may be used, redistributed and/or modified under the same terms
as Perl itself.
Added: branches/upstream/libscope-guard-perl/current/t/guard.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscope-guard-perl/current/t/guard.t?rev=54797&op=file
==============================================================================
--- branches/upstream/libscope-guard-perl/current/t/guard.t (added)
+++ branches/upstream/libscope-guard-perl/current/t/guard.t Fri Mar 26 05:13:26 2010
@@ -1,0 +1,47 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 8;
+
+BEGIN { use_ok('Scope::Guard', 'guard') };
+
+my $i = 1;
+
+{
+ guard { ok($i++ == 1, 'handler invoked at scope end') };
+}
+
+sub {
+ guard { ok($i++ == 2, 'handler invoked on return') };
+ return;
+}->();
+
+eval {
+ guard { ok($i++ == 3, 'handler invoked on exception') };
+ my $j = 0;
+ my $k = $j / $j;
+};
+
+like($@, qr{^Illegal division by zero}, 'exception was raised');
+
+{
+ my $guard = guard { ++$i };
+ $guard->dismiss();
+}
+
+ok($i++ == 4, 'dismiss() disables handler');
+
+{
+ my $guard = guard { ++$i };
+ $guard->dismiss(1);
+}
+
+ok($i++ == 5, 'dismiss(1) disables handler');
+
+{
+ my $guard = guard { ok($i++ == 6, 'dismiss(0) enables handler') };
+ $guard->dismiss();
+ $guard->dismiss(0);
+}
Added: branches/upstream/libscope-guard-perl/current/t/new.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscope-guard-perl/current/t/new.t?rev=54797&op=file
==============================================================================
--- branches/upstream/libscope-guard-perl/current/t/new.t (added)
+++ branches/upstream/libscope-guard-perl/current/t/new.t Fri Mar 26 05:13:26 2010
@@ -1,0 +1,52 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 8;
+
+BEGIN { use_ok('Scope::Guard') };
+
+my $i = 1;
+
+sub handler {
+ ok($i++ == 3, 'handler invoked on exception');
+}
+
+{
+ my $guard = Scope::Guard->new(sub { ok($i++ == 1, 'handler invoked at scope end') });
+}
+
+sub {
+ my $handler = sub { ok($i++ == 2, 'handler invoked on return') };
+ my $guard = Scope::Guard->new($handler);
+ return;
+}->();
+
+eval {
+ my $guard = Scope::Guard->new(\&handler);
+ my $j = 0;
+ my $k = $j / $j;
+};
+
+like($@, qr{^Illegal division by zero}, 'exception was raised');
+
+{
+ my $guard = Scope::Guard->new(sub { ++$i });
+ $guard->dismiss();
+}
+
+ok($i++ == 4, 'dismiss() disables handler');
+
+{
+ my $guard = Scope::Guard->new(sub { ++$i });
+ $guard->dismiss(1);
+}
+
+ok($i++ == 5, 'dismiss(1) disables handler');
+
+{
+ my $guard = Scope::Guard->new(sub { ok($i++ == 6, 'dismiss(0) enables handler') });
+ $guard->dismiss();
+ $guard->dismiss(0);
+}
Added: branches/upstream/libscope-guard-perl/current/t/scope_guard.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libscope-guard-perl/current/t/scope_guard.t?rev=54797&op=file
==============================================================================
--- branches/upstream/libscope-guard-perl/current/t/scope_guard.t (added)
+++ branches/upstream/libscope-guard-perl/current/t/scope_guard.t Fri Mar 26 05:13:26 2010
@@ -1,0 +1,52 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 8;
+
+BEGIN { use_ok('Scope::Guard', 'scope_guard') };
+
+my $i = 1;
+
+sub handler {
+ ok($i++ == 3, 'handler invoked on exception');
+}
+
+{
+ scope_guard sub { ok($i++ == 1, 'handler invoked at scope end') };
+}
+
+sub {
+ my $handler = sub { ok($i++ == 2, 'handler invoked on return') };
+ scope_guard $handler;
+ return;
+}->();
+
+eval {
+ scope_guard \&handler;
+ my $j = 0;
+ my $k = $j / $j;
+};
+
+like($@, qr{^Illegal division by zero}, 'exception was raised');
+
+{
+ my $guard = scope_guard sub { ++$i };
+ $guard->dismiss();
+}
+
+ok($i++ == 4, 'dismiss() disables handler');
+
+{
+ my $guard = scope_guard sub { ++$i };
+ $guard->dismiss(1);
+}
+
+ok($i++ == 5, 'dismiss(1) disables handler');
+
+{
+ my $guard = scope_guard sub { ok($i++ == 6, 'dismiss(0) enables handler') };
+ $guard->dismiss();
+ $guard->dismiss(0);
+}
More information about the Pkg-perl-cvs-commits
mailing list