ConditionSystem
view release on metacpan or search on metacpan
}
},
"runtime" : {
"requires" : {
"Moose" : "1.16",
"Scalar::Util" : "1.23",
"Scope::Upper" : "0.12",
"Sub::Exporter" : "0.982",
"Test::More" : "0.96",
"Throwable" : "0.102080",
"Try::Tiny" : "0.07"
}
}
},
"release_status" : "stable",
"version" : "0.02",
"x_Dist_Zilla" : {
"plugins" : [
{
"class" : "Dist::Zilla::Plugin::GatherDir",
"name" : "@Filter/GatherDir",
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: ConditionSystem
requires:
Moose: 1.16
Scalar::Util: 1.23
Scope::Upper: 0.12
Sub::Exporter: 0.982
Test::More: 0.96
Throwable: 0.102080
Try::Tiny: 0.07
version: 0.02
x_Dist_Zilla:
plugins:
-
class: Dist::Zilla::Plugin::GatherDir
name: '@Filter/GatherDir'
version: 4.102344
-
class: Dist::Zilla::Plugin::PruneCruft
name: '@Filter/PruneCruft'
Makefile.PL view on Meta::CPAN
'EXE_FILES' => [],
'LICENSE' => 'perl',
'NAME' => 'ConditionSystem',
'PREREQ_PM' => {
'Moose' => '1.16',
'Scalar::Util' => '1.23',
'Scope::Upper' => '0.12',
'Sub::Exporter' => '0.982',
'Test::More' => '0.96',
'Throwable' => '0.102080',
'Try::Tiny' => '0.07'
},
'VERSION' => '0.02',
'test' => {
'TESTS' => 't/*.t'
}
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) {
my $br = delete $WriteMakefileArgs{BUILD_REQUIRES};
[@Git]
[PodWeaver]
config_plugin = @FLORA
[Prereqs]
Scalar::Util = 1.23
Scope::Upper = 0.12
Sub::Exporter = 0.982
Try::Tiny = 0.07
[Prereq / tests]
Throwable = 0.102080
Test::More = 0.96
Moose = 1.16
lib/ConditionSystem.pm view on Meta::CPAN
BEGIN {
$ConditionSystem::VERSION = '0.02';
}
# ABSTRACT: A Common Lisp like condition/restart system for exceptions
use strict;
use warnings FATAL => 'all';
use Scope::Upper qw( unwind :words );
use Scalar::Util 'blessed';
use Try::Tiny;
use Sub::Exporter -setup => {
exports => [qw( restart with_handlers bind_continue handle restart_case )],
groups => {
default => [qw( restart with_handlers bind_continue handle restart_case )]
}
};
our %handlers;
our %cases;
BEGIN {
no strict 'refs';
*{'CORE::GLOBAL::die'} = sub {
my $err = shift;
for my $handles (keys %handlers) {
if($err->isa($handles)) {
my $handler = $handlers{$handles};
$handler = ${$handler}
if blessed($handler) && $handler->isa('Try::Tiny::Catch');
unwind $handler->($err) => UP UP HERE;
return "Well, it should never get here...";
}
}
};
};
sub with_handlers (&@) {
my ($code, %handles) = @_;
use strict;
use warnings FATAL => 'all';
use Test::More;
use ConditionSystem;
use Try::Tiny;
{
package MalformedLogEntry;
use Moose;
extends 'Throwable::Error';
has bad_data => ( is => 'ro' );
};
{
$here = 1
}),
handle(ENOBEER => sub {
$not_here = 1;
});
ok($here, 'Handled the correct exception');
ok(!$not_here, 'Did not handle other (unmatched) exceptions');
};
subtest 'handler_case + Try::Tiny' => sub {
my $here;
with_handlers {
InsufficientMoose->throw('Your Moose skills are weak old man');
}
handle InsufficientMoose => catch {
$here = 1;
};
ok($here, 'All is good in Try::Tiny land');
};
subtest 'restarts' => sub {
my ($started, $restarted, $invoked_restart, $restart_value);
my $risky_business = sub {
restart_case {
ENOBEER->new('How the hell am I meant to code now?')
}
bind_continue(use_me => sub {
( run in 0.657 second using v1.01-cache-2.11-cpan-05444aca049 )