From: Karen Etheridge Date: Wed, 14 Nov 2012 21:08:50 +0000 (-0800) Subject: C<> tags, minor punctuation and grammar fixes X-Git-Tag: Try-Tiny-0.12~4^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ad10a9e282b42a564ea987f0d60a2b7ece3e6d2d;p=p5sagit%2FTry-Tiny.git C<> tags, minor punctuation and grammar fixes --- diff --git a/lib/Try/Tiny.pm b/lib/Try/Tiny.pm index 18b91a3..43c7b9e 100644 --- a/lib/Try/Tiny.pm +++ b/lib/Try/Tiny.pm @@ -182,7 +182,7 @@ This module provides bare bones C/C/C statements that are d minimize common mistakes with eval blocks, and NOTHING else. This is unlike L which provides a nice syntax and avoids adding -another call stack layer, and supports calling C from the try block to +another call stack layer, and supports calling C from the C block to return from the parent subroutine. These extra features come at a cost of a few dependencies, namely L and L which are occasionally problematic, and the additional catch filtering uses L @@ -196,10 +196,10 @@ It's designed to work as correctly as possible in light of the various pathological edge cases (see L) and to be compatible with any style of error values (simple strings, references, objects, overloaded objects, etc). -If the try block dies, it returns the value of the last statement executed in -the catch block, if there is one. Otherwise, it returns C in scalar +If the C block dies, it returns the value of the last statement executed in +the C block, if there is one. Otherwise, it returns C in scalar context or the empty list in list context. The following examples all -assign C<"bar"> to C<$x>. +assign C<"bar"> to C<$x>: my $x = try { die "foo" } catch { "bar" }; my $x = try { die "foo" } || { "bar" }; @@ -207,15 +207,15 @@ assign C<"bar"> to C<$x>. my $x = eval { die "foo" } || "bar"; -You can add finally blocks making the following true. +You can add C blocks, yielding the following: my $x; try { die 'foo' } finally { $x = 'bar' }; try { die 'foo' } catch { warn "Got a die: $_" } finally { $x = 'bar' }; -Finally blocks are always executed making them suitable for cleanup code -which cannot be handled using local. You can add as many finally blocks to a -given try block as you like. +C blocks are always executed making them suitable for cleanup code +which cannot be handled using local. You can add as many C blocks to a +given C block as you like. =head1 EXPORTS @@ -228,7 +228,7 @@ L to get L's flexibility. =item try (&;@) -Takes one mandatory try subroutine, an optional catch subroutine & finally +Takes one mandatory C subroutine, an optional C subroutine and C subroutine. The mandatory subroutine is evaluated in the context of an C block. @@ -246,7 +246,7 @@ value it had before the C block was executed. Note that the error may be false, but if that happens the C block will still be invoked. -Once all execution is finished then the finally block if given will execute. +Once all execution is finished then the C block, if given, will execute. =item catch (&;$) @@ -258,7 +258,7 @@ with this code reference. catch { ... } -Inside the catch block the caught error is stored in C<$_>, while previous +Inside the C block the caught error is stored in C<$_>, while previous value of C<$@> is still available for use. This value may or may not be meaningful depending on what happened before the C, but it might be a good idea to preserve it in an error stack. @@ -285,14 +285,14 @@ Or even finally { ... } catch { ... }; -Intended to be the second or third element of C. Finally blocks are always +Intended to be the second or third element of C. C blocks are always executed in the event of a successful C or if C is run. This allows you to locate cleanup code which cannot be done via C e.g. closing a file handle. -When invoked, the finally block is passed the error that was caught. If no -error was caught, it is passed nothing. (Note that the finally block does not -localize C<$_> with the error, since unlike in a catch block, there is no way +When invoked, the C block is passed the error that was caught. If no +error was caught, it is passed nothing. (Note that the C block does not +localize C<$_> with the error, since unlike in a C block, there is no way to know if C<$_ == undef> implies that there were no errors.) In other words, the following code does just what you would expect: @@ -308,7 +308,7 @@ the following code does just what you would expect: } }; -B. C will +B block>. C will not do anything about handling possible errors coming from code located in these blocks. @@ -323,7 +323,7 @@ There are a number of issues with C. =head2 Clobbering $@ -When you run an eval block and it succeeds, C<$@> will be cleared, potentially +When you run an C block and it succeeds, C<$@> will be cleared, potentially clobbering an error that is currently being caught. This causes action at a distance, clearing previous errors your caller may have @@ -341,7 +341,7 @@ the localization) in the beginning of the C block. =head2 Localizing $@ silently masks errors -Inside an eval block C behaves sort of like: +Inside an C block, C behaves sort of like: sub die { $@ = $_[0]; @@ -400,7 +400,7 @@ been cleared by C in the destructor. The workaround for this is even uglier than the previous ones. Even though we can't save the value of C<$@> from code that doesn't localize, we can at least -be sure the eval was aborted due to an error: +be sure the C was aborted due to an error: my $failed = not eval { ... @@ -480,8 +480,8 @@ Instead, you should capture the return value: say "This text WILL NEVER appear!"; } -Note that if you have a catch block, it must return undef for this to work, -since if a catch block exists, its return value is returned in place of undef +Note that if you have a C block, it must return C for this to work, +since if a C block exists, its return value is returned in place of C when an exception is thrown. =item *