Hello community, here is the log from the commit of package perl-Try-Tiny for openSUSE:Factory checked in at Mon Sep 19 21:38:39 CEST 2011.
-------- --- perl-Try-Tiny/perl-Try-Tiny.changes 2011-05-17 14:14:42.000000000 +0200 +++ /mounts/work_src_done/STABLE/perl-Try-Tiny/perl-Try-Tiny.changes 2011-09-19 11:10:01.000000000 +0200 @@ -1,0 +2,7 @@ +Mon Sep 19 09:04:58 UTC 2011 - [email protected] + +- updated to 0.11 + - fix broken dist + - clarify some docs + +------------------------------------------------------------------- calling whatdependson for head-i586 Old: ---- Try-Tiny-0.09.tar.gz New: ---- Try-Tiny-0.11.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Try-Tiny.spec ++++++ --- /var/tmp/diff_new_pack.7SBBQv/_old 2011-09-19 21:38:35.000000000 +0200 +++ /var/tmp/diff_new_pack.7SBBQv/_new 2011-09-19 21:38:35.000000000 +0200 @@ -18,11 +18,11 @@ Name: perl-Try-Tiny -Version: 0.09 +Version: 0.11 Release: 1 License: MIT %define cpan_name Try-Tiny -Summary: minimal try/catch with proper localization of $@ +Summary: Minimal try/catch with proper localization of $@ Url: http://search.cpan.org/dist/Try-Tiny/ Group: Development/Libraries/Perl Source: http://www.cpan.org/authors/id/D/DO/DOY/%{cpan_name}-%{version}.tar.gz @@ -49,6 +49,30 @@ who still want to write correct 'eval' blocks without 5 lines of boilerplate each time. +It's designed to work as correctly as possible in light of the various +pathological edge cases (see the BACKGROUND manpage) 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 'undef' in +scalar context or the empty list in list context. The following two +examples both assign '"bar"' to '$x'. + + my $x = try { die "foo" } catch { "bar" }; + + my $x = eval { die "foo" } || "bar"; + +You can add finally blocks making the following true. + + 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. + %prep %setup -q -n %{cpan_name}-%{version} @@ -64,9 +88,6 @@ %perl_process_packlist %perl_gen_filelist -%clean -%{__rm} -rf %{buildroot} - %files -f %{name}.files %defattr(-,root,root,755) %doc Changes ++++++ Try-Tiny-0.09.tar.gz -> Try-Tiny-0.11.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Try-Tiny-0.09/Changes new/Try-Tiny-0.11/Changes --- old/Try-Tiny-0.09/Changes 2010-11-28 23:41:49.000000000 +0100 +++ new/Try-Tiny-0.11/Changes 2011-08-30 17:50:00.000000000 +0200 @@ -1,3 +1,9 @@ +0.11 + - fix broken dist + +0.10 + - clarify some docs + 0.09 - don't index Try::Tiny::ScopeGuard diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Try-Tiny-0.09/MANIFEST new/Try-Tiny-0.11/MANIFEST --- old/Try-Tiny-0.09/MANIFEST 2010-11-28 23:43:37.000000000 +0100 +++ new/Try-Tiny-0.11/MANIFEST 2011-08-30 17:50:50.000000000 +0200 @@ -4,6 +4,7 @@ MANIFEST This list of files MANIFEST.SKIP t/basic.t +t/context.t t/finally.t t/given_when.t t/when.t diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Try-Tiny-0.09/META.yml new/Try-Tiny-0.11/META.yml --- old/Try-Tiny-0.09/META.yml 2010-11-28 23:43:37.000000000 +0100 +++ new/Try-Tiny-0.11/META.yml 2011-08-30 17:50:50.000000000 +0200 @@ -1,6 +1,6 @@ --- #YAML:1.0 name: Try-Tiny -version: 0.09 +version: 0.11 abstract: ~ author: [] license: unknown diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Try-Tiny-0.09/lib/Try/Tiny.pm new/Try-Tiny-0.11/lib/Try/Tiny.pm --- old/Try-Tiny-0.09/lib/Try/Tiny.pm 2010-11-28 23:42:11.000000000 +0100 +++ new/Try-Tiny-0.11/lib/Try/Tiny.pm 2011-08-30 17:50:14.000000000 +0200 @@ -10,7 +10,7 @@ @ISA = qw(Exporter); } -$VERSION = "0.09"; +$VERSION = "0.11"; $VERSION = eval $VERSION; @@ -157,6 +157,9 @@ =head1 SYNOPSIS +You can use Try::Tiny's C<try> and C<catch> to expect and handle exceptional +conditions, avoiding quirks in Perl and common mistakes: + # handle errors with a catch handler try { die "foo"; @@ -164,6 +167,10 @@ warn "caught error: $_"; # not $@ }; +You can also use it like a stanalone C<eval> to catch and ignore any error +conditions. Obviously, this is an extreme measure not to be undertaken +lightly: + # just silence errors try { die "foo"; @@ -282,8 +289,10 @@ handle. When invoked, the finally block is passed the error that was caught. If no -error was caught, it is passed nothing. In other words, the following code -does just what you would expect: +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 +to know if C<$_ == undef> implies that there were no errors.) In other words, +the following code does just what you would expect: try { die_sometimes(); @@ -446,12 +455,32 @@ C<return> returns from the C<try> block, not from the parent sub (note that this is also how C<eval> works, but not how L<TryCatch> works): - sub bar { - try { return "foo" }; - return "baz"; - } + sub parent_sub { + try { + die; + } + catch { + return; + }; + + say "this text WILL be displayed, even though an exception is thrown"; + } + +Instead, you should capture the return value: + + sub parent_sub { + my $success = try { + die; + 1; + } + return unless $success; + + say "This text WILL NEVER appear!"; + } - say bar(); # "baz" +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 +when an exception is thrown. =item * diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Try-Tiny-0.09/t/context.t new/Try-Tiny-0.11/t/context.t --- old/Try-Tiny-0.09/t/context.t 1970-01-01 01:00:00.000000000 +0100 +++ new/Try-Tiny-0.11/t/context.t 2011-04-28 23:53:04.000000000 +0200 @@ -0,0 +1,66 @@ +use strict; +use warnings; + +use Test::More; + +BEGIN { + plan tests => + 1 # use_ok + + (4+1) * 2 # list/scalar with exception (try + catch + 2 x finally) + is_deeply + + 4 # void with exception + + (3+1) * 2 # list/scalar no exception (try + 2 x finally) + is_deeply + + 3 # void no exception + ; + + use_ok 'Try::Tiny'; +} + +my $ctx_index = { + VOID => undef, + LIST => 1, + SCALAR => '', +}; +my ($ctx, $die); + +for (sort keys %$ctx_index) { + $ctx = $_; + for (0,1) { + $die = $_; + if ($ctx_index->{$ctx}) { + is_deeply( + [ run() ], + [ $die ? 'catch' : 'try' ], + ); + } + elsif (defined $ctx_index->{$ctx}) { + is_deeply( + [ scalar run() ], + [ $die ? 'catch' : 'try' ], + ); + } + else { + run(); + 1; + } + } +} + +sub run { + try { + is (wantarray, $ctx_index->{$ctx}, "Proper context $ctx in try{}"); + die if $die; + return 'try'; + } + catch { + is (wantarray, $ctx_index->{$ctx}, "Proper context $ctx in catch{}"); + return 'catch'; + } + finally { + is (wantarray, undef, "Proper VOID context in finally{} 1"); + return 'finally'; + } + finally { + is (wantarray, undef, "Proper VOID context in finally{} 2"); + return 'finally'; + }; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Try-Tiny-0.09/t/finally.t new/Try-Tiny-0.11/t/finally.t --- old/Try-Tiny-0.09/t/finally.t 2010-11-28 23:03:34.000000000 +0100 +++ new/Try-Tiny-0.11/t/finally.t 2011-04-28 00:30:35.000000000 +0200 @@ -3,7 +3,7 @@ use strict; #use warnings; -use Test::More tests => 13; +use Test::More tests => 24; BEGIN { use_ok 'Try::Tiny' }; @@ -74,4 +74,31 @@ }; }; +$_ = "foo"; +try { + is($_, "foo", "not localized in try"); +} +catch { +} +finally { + is(scalar(@_), 0, "nothing in \@_ (finally)"); + is($_, "foo", "\$_ not localized (finally)"); +}; +is($_, "foo", "same afterwards"); + +$_ = "foo"; +try { + is($_, "foo", "not localized in try"); + die "bar\n"; +} +catch { + is($_[0], "bar\n", "error in \@_ (catch)"); + is($_, "bar\n", "error in \$_ (catch)"); +} +finally { + is(scalar(@_), 1, "error in \@_ (finally)"); + is($_[0], "bar\n", "error in \@_ (finally)"); + is($_, "foo", "\$_ not localized (finally)"); +}; +is($_, "foo", "same afterwards"); 1; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun... -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
