| 1 | package ConditionSystem; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | $ConditionSystem::VERSION = '0.02'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | # ABSTRACT: A Common Lisp like condition/restart system for exceptions | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Scope::Upper qw( unwind :words ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Sub::Exporter -setup => { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | exports => [qw( restart with_handlers bind_continue handle restart_case )], | ||||||||||||||||||||||||||||
| 16 | groups => { | ||||||||||||||||||||||||||||
| 17 | default => [qw( restart with_handlers bind_continue handle restart_case )] | ||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | 2 | }; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | our %handlers; | |||||||||||||||||||||||||||
| 23 | 2 | our %cases; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | *{'CORE::GLOBAL::die'} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||
| 28 | 4 | my $err = shift; | |||||||||||||||||||||||||||
| 29 | 4 | for my $handles (keys %handlers) { | |||||||||||||||||||||||||||
| 30 | 4 | ▶ | if($err->isa($handles)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 4 | my $handler = $handlers{$handles}; | |||||||||||||||||||||||||||
| 32 | 4 | ▶ | $handler = ${$handler} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($handler) and $handler->isa("Try::Tiny::Catch")
MC/DC50%1/2
builtin::blessed($handler) and $handler->isa("Try::Tiny::Catch")
builtin::blessed($handler)
$handler->isa("Try::Tiny::Catch")
Truth table66%2/3
A and B
A= builtin::blessed($handler)B= $handler->isa("Try::Tiny::Catch")
| |||||||||||||||||||||||||||||
| 33 | if blessed($handler) && $handler->isa('Try::Tiny::Catch'); | ||||||||||||||||||||||||||||
| 34 | 4 | unwind $handler->($err) => UP UP HERE; | |||||||||||||||||||||||||||
| 35 | 0 | return "Well, it should never get here..."; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 2 | }; | |||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 4 | ▶ | sub with_handlers (&@) { | ||||||||||||||||||||||||||
|
Subroutine
with_handlers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 4 | my ($code, %handles) = @_; | |||||||||||||||||||||||||||
| 44 | 4 | %handlers = %handles; # XXX Should push onto each handler as a queue | |||||||||||||||||||||||||||
| 45 | 4 | my @ret = $code->(); | |||||||||||||||||||||||||||
| 46 | 4 | %handlers = (); | |||||||||||||||||||||||||||
| 47 | 4 | return @ret; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub continue_with (&) { | ||||||||||||||||||||||||||
|
Subroutine
continue_with: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 0 | my @vals = @_; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | return sub { @vals } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 54 | 0 | } | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | sub restart { | ||||||||||||||||||||||||||
|
Subroutine
restart: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 2 | my $name = shift; | |||||||||||||||||||||||||||
| 59 | 2 | my @args = @_; | |||||||||||||||||||||||||||
| 60 | 2 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 2 | $cases{$name}->(@args) | |||||||||||||||||||||||||||
| 62 | 2 | }; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub restart_case (&@) { | ||||||||||||||||||||||||||
|
Subroutine
restart_case: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 2 | my $error = shift->(); | |||||||||||||||||||||||||||
| 68 | 2 | %cases = @_; | |||||||||||||||||||||||||||
| 69 | 2 | die $error; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Nom. Sugarz | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 5 | ▶ | sub handle { | ||||||||||||||||||||||||||
|
Subroutine
handle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 5 | my ($handles, $code) = @_; | |||||||||||||||||||||||||||
| 77 | 5 | return $handles => $code; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | ▶ | sub bind_continue { | ||||||||||||||||||||||||||
|
Subroutine
bind_continue: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 4 | my ($restart, $code) = @_; | |||||||||||||||||||||||||||
| 83 | 4 | return $restart => $code; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||