r77131 - in /branches/upstream/libguard-perl/current: Changes Guard.pm MANIFEST META.json META.yml README

fabreg-guest at users.alioth.debian.org fabreg-guest at users.alioth.debian.org
Mon Jul 4 21:21:33 UTC 2011


Author: fabreg-guest
Date: Mon Jul  4 21:21:21 2011
New Revision: 77131

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=77131
Log:
[svn-upgrade] new version libguard-perl (1.022)

Added:
    branches/upstream/libguard-perl/current/META.json
Removed:
    branches/upstream/libguard-perl/current/META.yml
Modified:
    branches/upstream/libguard-perl/current/Changes
    branches/upstream/libguard-perl/current/Guard.pm
    branches/upstream/libguard-perl/current/MANIFEST
    branches/upstream/libguard-perl/current/README

Modified: branches/upstream/libguard-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libguard-perl/current/Changes?rev=77131&op=diff
==============================================================================
--- branches/upstream/libguard-perl/current/Changes (original)
+++ branches/upstream/libguard-perl/current/Changes Mon Jul  4 21:21:21 2011
@@ -1,5 +1,11 @@
 Revision history for Perl extension Guard
 
+1.022 Sat Jul  2 02:38:21 CEST 2011
+	- document how () after the function name overrides the
+          prototype.
+        - improve documentation, fix the examples.
+
+1.021 Sun Jul 19 07:43:17 CEST 2009
 	- try to provide compatibility to pre-5.8.8.
 
 1.02 Sat Apr 11 06:42:06 CEST 2009

Modified: branches/upstream/libguard-perl/current/Guard.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libguard-perl/current/Guard.pm?rev=77131&op=diff
==============================================================================
--- branches/upstream/libguard-perl/current/Guard.pm (original)
+++ branches/upstream/libguard-perl/current/Guard.pm Mon Jul  4 21:21:21 2011
@@ -44,7 +44,7 @@
 no warnings;
 
 BEGIN {
-   $VERSION = '1.021';
+   $VERSION = '1.022';
    @ISA = qw(Exporter);
    @EXPORT = qw(guard scope_guard);
 
@@ -57,6 +57,8 @@
 our $DIED = sub { warn "$@" };
 
 =item scope_guard BLOCK
+
+=item scope_guard ($coderef)
 
 Registers a block that is executed when the current scope (block,
 function, method, eval etc.) is exited.
@@ -105,13 +107,13 @@
 
 =item my $guard = guard BLOCK
 
+=item my $guard = guard ($coderef)
+
 Behaves the same as C<scope_guard>, except that instead of executing
 the block on scope exit, it returns an object whose lifetime determines
 when the BLOCK gets executed: when the last reference to the object gets
 destroyed, the BLOCK gets executed as with C<scope_guard>.
 
-The returned object can be copied as many times as you want.
-
 See the EXCEPTIONS section for an explanation of how exceptions
 (i.e. C<die>) are handled inside guard blocks.
 
@@ -121,7 +123,7 @@
 method that does this already):
 
    use Guard;
-   use AnyEvent;
+   use Coro::AnyEvent;
    use Coro::Semaphore;
 
    my $sem = new Coro::Semaphore;
@@ -130,21 +132,18 @@
       $sem->down;
       my $guard = guard { $sem->up };
 
-      my $timer;
-      $timer = AnyEvent->timer (after => 1, sub {
-         # do something
-         undef $sem;
-         undef $timer;
-      });
+      Coro::AnyEvent::sleep 1;
+
+      # $sem->up gets executed when returning
    }
 
 The advantage of doing this with a guard instead of simply calling C<<
 $sem->down >> in the callback is that you can opt not to create the timer,
-or your code can throw an exception before it can create the timer, or you
-can create multiple timers or other event watchers and only when the last
-one gets executed will the lock be unlocked. Using the C<guard>, you do
-not have to worry about catching all the places where you have to unlock
-the semaphore.
+or your code can throw an exception before it can create the timer (or
+the thread gets canceled), or you can create multiple timers or other
+event watchers and only when the last one gets executed will the lock be
+unlocked. Using the C<guard>, you do not have to worry about catching all
+the places where you have to unlock the semaphore.
 
 =item $guard->cancel
 
@@ -152,8 +151,8 @@
 C<guard> function, i.e. it will free the BLOCK originally passed to
 C<guard >and will arrange for the BLOCK not to be executed.
 
-This can be useful when you use C<guard> to create a fatal cleanup handler
-and later decide it is no longer needed.
+This can be useful when you use C<guard> to create a cleanup handler to be
+called under fatal conditions and later decide it is no longer needed.
 
 =cut
 
@@ -164,21 +163,22 @@
 =head1 EXCEPTIONS
 
 Guard blocks should not normally throw exceptions (that is, C<die>). After
-all, they are usually used to clean up after such exceptions. However, if
-something truly exceptional is happening, a guard block should be allowed
-to die. Also, programming errors are a large source of exceptions, and the
-programmer certainly wants to know about those.
+all, they are usually used to clean up after such exceptions. However,
+if something truly exceptional is happening, a guard block should of
+course be allowed to die. Also, programming errors are a large source of
+exceptions, and the programmer certainly wants to know about those.
 
 Since in most cases, the block executing when the guard gets executed does
 not know or does not care about the guard blocks, it makes little sense to
 let containing code handle the exception.
 
-Therefore, whenever a guard block throws an exception, it will be caught,
-followed by calling the code reference stored in C<$Guard::DIED> (with
-C<$@> set to the actual exception), which is similar to how most event
-loops handle this case.
-
-The default for C<$Guard::DIED> is to call C<warn "$@">.
+Therefore, whenever a guard block throws an exception, it will be caught
+by Guard, followed by calling the code reference stored in C<$Guard::DIED>
+(with C<$@> set to the actual exception), which is similar to how most
+event loops handle this case.
+
+The default for C<$Guard::DIED> is to call C<warn "$@">, i.e. the error is
+printed as a warning and the program continues.
 
 The C<$@> variable will be restored to its value before the guard call in
 all cases, so guards will not disturb C<$@> in any way.
@@ -199,11 +199,15 @@
 =head1 SEE ALSO
 
 L<Scope::Guard> and L<Sub::ScopeFinalizer>, which actually implement
-dynamic, not scoped guards, and have a lot higher CPU, memory and typing
+dynamically scoped guards only, not the lexically scoped guards that their
+documentation promises, and have a lot higher CPU, memory and typing
 overhead.
 
-L<Hook::Scope>, which has apparently never been finished and corrupts
+L<Hook::Scope>, which has apparently never been finished and can corrupt
 memory when used.
 
+L<Scope::Guard> seems to have a big SEE ALSO section for even more
+modules like it.
+
 =cut
 

Modified: branches/upstream/libguard-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libguard-perl/current/MANIFEST?rev=77131&op=diff
==============================================================================
--- branches/upstream/libguard-perl/current/MANIFEST (original)
+++ branches/upstream/libguard-perl/current/MANIFEST Mon Jul  4 21:21:21 2011
@@ -9,4 +9,4 @@
 t/01_scoped.t
 t/02_guard.t
 t/03_die.t
-META.yml                                 Module meta-data (added by MakeMaker)
+META.json                                Module meta-data (added by MakeMaker)

Added: branches/upstream/libguard-perl/current/META.json
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libguard-perl/current/META.json?rev=77131&op=file
==============================================================================
--- branches/upstream/libguard-perl/current/META.json (added)
+++ branches/upstream/libguard-perl/current/META.json Mon Jul  4 21:21:21 2011
@@ -1,0 +1,26 @@
+{
+   "no_index" : {
+      "directory" : [
+         "t",
+         "inc"
+      ]
+   },
+   "meta-spec" : {
+      "version" : 1.4,
+      "url" : "http://module-build.sourceforge.net/META-spec-v1.4.html"
+   },
+   "generated_by" : "ExtUtils::MakeMaker::JSONMETA version 7.000",
+   "distribution_type" : "module",
+   "version" : "1.022",
+   "name" : "Guard",
+   "author" : [],
+   "license" : "unknown",
+   "build_requires" : {
+      "ExtUtils::MakeMaker" : 0
+   },
+   "requires" : {},
+   "abstract" : null,
+   "configure_requires" : {
+      "ExtUtils::MakeMaker" : 0
+   }
+}

Modified: branches/upstream/libguard-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libguard-perl/current/README?rev=77131&op=diff
==============================================================================
--- branches/upstream/libguard-perl/current/README (original)
+++ branches/upstream/libguard-perl/current/README Mon Jul  4 21:21:21 2011
@@ -32,6 +32,7 @@
     default.
 
     scope_guard BLOCK
+    scope_guard ($coderef)
         Registers a block that is executed when the current scope (block,
         function, method, eval etc.) is exited.
 
@@ -79,13 +80,12 @@
            }
 
     my $guard = guard BLOCK
+    my $guard = guard ($coderef)
         Behaves the same as "scope_guard", except that instead of executing
         the block on scope exit, it returns an object whose lifetime
         determines when the BLOCK gets executed: when the last reference to
         the object gets destroyed, the BLOCK gets executed as with
         "scope_guard".
-
-        The returned object can be copied as many times as you want.
 
         See the EXCEPTIONS section for an explanation of how exceptions
         (i.e. "die") are handled inside guard blocks.
@@ -96,7 +96,7 @@
         method that does this already):
 
            use Guard;
-           use AnyEvent;
+           use Coro::AnyEvent;
            use Coro::Semaphore;
 
            my $sem = new Coro::Semaphore;
@@ -105,47 +105,48 @@
               $sem->down;
               my $guard = guard { $sem->up };
 
-              my $timer;
-              $timer = AnyEvent->timer (after => 1, sub {
-                 # do something
-                 undef $sem;
-                 undef $timer;
-              });
+              Coro::AnyEvent::sleep 1;
+
+              # $sem->up gets executed when returning
            }
 
         The advantage of doing this with a guard instead of simply calling
         "$sem->down" in the callback is that you can opt not to create the
         timer, or your code can throw an exception before it can create the
-        timer, or you can create multiple timers or other event watchers and
-        only when the last one gets executed will the lock be unlocked.
-        Using the "guard", you do not have to worry about catching all the
-        places where you have to unlock the semaphore.
+        timer (or the thread gets canceled), or you can create multiple
+        timers or other event watchers and only when the last one gets
+        executed will the lock be unlocked. Using the "guard", you do not
+        have to worry about catching all the places where you have to unlock
+        the semaphore.
 
     $guard->cancel
         Calling this function will "disable" the guard object returned by
         the "guard" function, i.e. it will free the BLOCK originally passed
         to "guard "and will arrange for the BLOCK not to be executed.
 
-        This can be useful when you use "guard" to create a fatal cleanup
-        handler and later decide it is no longer needed.
+        This can be useful when you use "guard" to create a cleanup handler
+        to be called under fatal conditions and later decide it is no longer
+        needed.
 
 EXCEPTIONS
     Guard blocks should not normally throw exceptions (that is, "die").
     After all, they are usually used to clean up after such exceptions.
     However, if something truly exceptional is happening, a guard block
-    should be allowed to die. Also, programming errors are a large source of
-    exceptions, and the programmer certainly wants to know about those.
+    should of course be allowed to die. Also, programming errors are a large
+    source of exceptions, and the programmer certainly wants to know about
+    those.
 
     Since in most cases, the block executing when the guard gets executed
     does not know or does not care about the guard blocks, it makes little
     sense to let containing code handle the exception.
 
-    Therefore, whenever a guard block throws an exception, it will be
-    caught, followed by calling the code reference stored in $Guard::DIED
+    Therefore, whenever a guard block throws an exception, it will be caught
+    by Guard, followed by calling the code reference stored in $Guard::DIED
     (with $@ set to the actual exception), which is similar to how most
     event loops handle this case.
 
-    The default for $Guard::DIED is to call "warn "$@"".
+    The default for $Guard::DIED is to call "warn "$@"", i.e. the error is
+    printed as a warning and the program continues.
 
     The $@ variable will be restored to its value before the guard call in
     all cases, so guards will not disturb $@ in any way.
@@ -162,10 +163,14 @@
     solution to the problem of exceptions.
 
 SEE ALSO
-    Scope::Guard and Sub::ScopeFinalizer, which actually implement dynamic,
-    not scoped guards, and have a lot higher CPU, memory and typing
-    overhead.
+    Scope::Guard and Sub::ScopeFinalizer, which actually implement
+    dynamically scoped guards only, not the lexically scoped guards that
+    their documentation promises, and have a lot higher CPU, memory and
+    typing overhead.
 
-    Hook::Scope, which has apparently never been finished and corrupts
+    Hook::Scope, which has apparently never been finished and can corrupt
     memory when used.
 
+    Scope::Guard seems to have a big SEE ALSO section for even more modules
+    like it.
+




More information about the Pkg-perl-cvs-commits mailing list