pax_global_header00006660000000000000000000000064122353717140014517gustar00rootroot0000000000000052 comment=76dd503faee2b87ec7cc5a4ce6effcd3a47fd7cd libtry-tiny-byclass-perl-0.01/000077500000000000000000000000001223537171400163235ustar00rootroot00000000000000libtry-tiny-byclass-perl-0.01/Changes000066400000000000000000000001651223537171400176200ustar00rootroot00000000000000Revision history for Try-Tiny-ByClass 0.01 2013-01-04 First version, released on an unsuspecting world. libtry-tiny-byclass-perl-0.01/MANIFEST000066400000000000000000000003721223537171400174560ustar00rootroot00000000000000Changes MANIFEST Makefile.PL README lib/Try/Tiny/ByClass.pm t/00-load.t t/basic.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) libtry-tiny-byclass-perl-0.01/META.json000066400000000000000000000020711223537171400177440ustar00rootroot00000000000000{ "abstract" : "unknown", "author" : [ "Lukas Mai " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.120921", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Try-Tiny-ByClass", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "IO::Handle" : "0", "Test::More" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.56" } }, "runtime" : { "requires" : { "Dispatch::Class" : "0", "Exporter" : "0", "Try::Tiny" : "0", "base" : "0", "perl" : "5.006000", "strict" : "0", "warnings" : "0" } } }, "release_status" : "stable", "resources" : {}, "version" : "0.01" } libtry-tiny-byclass-perl-0.01/META.yml000066400000000000000000000010741223537171400175760ustar00rootroot00000000000000--- abstract: unknown author: - 'Lukas Mai ' build_requires: IO::Handle: 0 Test::More: 0 configure_requires: ExtUtils::MakeMaker: 6.56 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.120921' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Try-Tiny-ByClass no_index: directory: - t - inc requires: Dispatch::Class: 0 Exporter: 0 Try::Tiny: 0 base: 0 perl: 5.006000 strict: 0 warnings: 0 resources: {} version: 0.01 libtry-tiny-byclass-perl-0.01/Makefile.PL000066400000000000000000000020611223537171400202740ustar00rootroot00000000000000use 5.006; use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Try::Tiny::ByClass', AUTHOR => q{Lukas Mai }, VERSION_FROM => 'lib/Try/Tiny/ByClass.pm', CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => '6.56', }, LICENSE => 'perl', PL_FILES => {}, BUILD_REQUIRES => { 'Test::More' => 0, 'IO::Handle' => 0, }, PREREQ_PM => { 'warnings' => 0, 'strict' => 0, 'base' => 0, 'Exporter' => 0, 'Try::Tiny' => 0, 'Dispatch::Class' => 0, }, MIN_PERL_VERSION => '5.6.0', META_MERGE => { resources => { repository => { url => 'git://github.com/mauke/Try-Tiny-ByClass.git', web => 'https://github.com/mauke/Try-Tiny-ByClass', type => 'git', }, }, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Try-Tiny-ByClass-*' }, ); libtry-tiny-byclass-perl-0.01/README000066400000000000000000000017671223537171400172160ustar00rootroot00000000000000Try-Tiny-ByClass selectively catch exceptions by class name INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc Try::Tiny::ByClass You can also look for information at: RT, CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=Try-Tiny-ByClass AnnoCPAN, Annotated CPAN documentation http://annocpan.org/dist/Try-Tiny-ByClass CPAN Ratings http://cpanratings.perl.org/d/Try-Tiny-ByClass Search CPAN http://search.cpan.org/dist/Try-Tiny-ByClass/ COPYRIGHT AND LICENCE Copyright (C) 2013 Lukas Mai This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. libtry-tiny-byclass-perl-0.01/lib/000077500000000000000000000000001223537171400170715ustar00rootroot00000000000000libtry-tiny-byclass-perl-0.01/lib/Try/000077500000000000000000000000001223537171400176475ustar00rootroot00000000000000libtry-tiny-byclass-perl-0.01/lib/Try/Tiny/000077500000000000000000000000001223537171400205725ustar00rootroot00000000000000libtry-tiny-byclass-perl-0.01/lib/Try/Tiny/ByClass.pm000066400000000000000000000035171223537171400224760ustar00rootroot00000000000000package Try::Tiny::ByClass; use warnings; use strict; our $VERSION = '0.01'; use base qw(Exporter); our @EXPORT = our @EXPORT_OK = qw(try catch finally catch_case); use Try::Tiny qw(try catch finally); use Dispatch::Class qw(dispatch); sub catch_case ($@) { my $handlers = shift; &catch(dispatch(@$handlers, '*' => sub { die $_[0] }), @_) } 'ok' __END__ =head1 NAME Try::Tiny::ByClass - selectively catch exceptions by class name =head1 SYNOPSIS use Try::Tiny::ByClass; try { die $exception_object; } catch_case [ 'Some::Class' => sub { # handle Some::Class exceptions }, 'Exception::DivByZero' => sub { # handle Exception::DivByZero exceptions }, ], finally { # always do this }; =head1 DESCRIPTION This module is a simple wrapper around L|Try::Tiny>, which see. It re-exports L|Try::Tiny/try->, L|Try::Tiny/catch->, and L|Try::Tiny/finally->. In addition, it provides a way to catch only some exceptions by filtering on the class (including superclasses and consumed roles) of an exception object. =head2 Functions =over =item catch_case ($;@) Intended to be used instead of L|Try::Tiny/catch-> in the second argument position of L|Try::Tiny/try->. Instead of a block it takes a reference to an array of C<< CLASS => CODEREF >> pairs, which it passes on to C in L|Dispatch::Class>. =back =head1 SEE ALSO L, L =head1 AUTHOR Lukas Mai, C<< >> =head1 COPYRIGHT & LICENSE Copyright 2013 Lukas Mai. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut libtry-tiny-byclass-perl-0.01/t/000077500000000000000000000000001223537171400165665ustar00rootroot00000000000000libtry-tiny-byclass-perl-0.01/t/00-load.t000066400000000000000000000002411223537171400201040ustar00rootroot00000000000000#!perl use Test::More tests => 1; BEGIN { use_ok( 'Try::Tiny::ByClass' ); } diag( "Testing Try::Tiny::ByClass $Try::Tiny::ByClass::VERSION, Perl $], $^X" ); libtry-tiny-byclass-perl-0.01/t/basic.t000066400000000000000000000033031223537171400200330ustar00rootroot00000000000000#!perl use warnings FATAL => 'all'; use strict; use Test::More tests => 19; use Try::Tiny::ByClass; use IO::Handle (); { my $val; my $x = try { die "asdf"; } catch_case [ ':str' => sub { 42 }, ], finally { $val = 'xyzzy'; }; is $x, 42; is $val, 'xyzzy'; } { package DummyClass; sub new { bless {}, $_[0] } sub subclass { my $class = shift; for my $subclass (@_) { no strict 'refs'; push @{$subclass . '::ISA'}, $class; } } } DummyClass->subclass(qw(Some::Class Other::Class)); { my @catch_case = catch_case [ 'Some::Class' => sub { 1 }, 'Other::Class' => sub { 2 }, 'UNIVERSAL' => sub { "???" }, ]; is +(try { die Other::Class->new } @catch_case), 2; is +(try { die IO::Handle->new } @catch_case), "???"; is +( try { try { die ["not an object"] } @catch_case; ok 0; } catch { is_deeply $_, ["not an object"]; 'k' } ), 'k'; } DummyClass->subclass(qw(Mammal Tree)); Mammal->subclass(qw(Dog Bunny)); Dog->subclass(qw(Dog::Tiny Barky Setter)); Tree->subclass(qw(Barky)); my @trace; my @catches = catch_case [ map { my $class = $_; $_ => sub { push @trace, $class; return $class, $_[0]; } } qw( Tree Dog::Tiny Dog ARRAY Mammal :str HASH * ) ]; my @prep = ( 'Tree' => Tree->new, 'Mammal' => Mammal->new, 'Dog' => Dog->new, 'Mammal' => Bunny->new, 'Dog::Tiny' => Dog::Tiny->new, 'Tree' => Barky->new, 'Dog' => Setter->new, 'ARRAY' => [1, 2, 3], 'HASH' => {A => 'b'}, ':str' => "foo bar\n", ':str' => "5\n", '*' => IO::Handle->new, ); my @ks; for (my $i = 0; $i < @prep; $i += 2) { my ($k, $v) = @prep[$i, $i + 1]; my @got = try { die $v } @catches; is_deeply \@got, [$k, $v]; push @ks, $k; } is_deeply \@trace, \@ks;