| 1 | package Venus::Role::Throwable; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 61 | ▶ | use 5.018; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 61 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 61 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 61 | ▶ | use Venus::Role 'with'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | # METHODS | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | sub throw { | ||||||||||||||||||||
| 13 | 32 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||
|
Subroutine
throw: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 32 | my $context = (caller(1))[3]; | |||||||||||||||||||
| 16 | 32 | ▶ | my $package = $name || join('::', map ucfirst, ref($self), 'error'); | ||||||||||||||||||
|
Condition33%1/3
$name || join('::', map(ucfirst($_), ref $self, 'error'))
MC/DC0%0/2
$name || join('::', map(ucfirst($_), ref $self, 'error'))
$name
join('::', map(ucfirst($_), ref $self, 'error'))
Truth table33%1/3
A || B
A= $nameB= join('::', map(ucfirst($_), ref $self, 'error'))
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 32 | require Venus::Throw; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 32 | return Venus::Throw->new(package => $package, context => $context); | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | # EXPORTS | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | sub EXPORT { | ||||||||||||||||||||
| 26 | 63 | ▶ | ['throw'] | ||||||||||||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 61 | 1; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =head1 NAME | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | Venus::Role::Throwable - Throwable Role | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =head1 ABSTRACT | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | Throwable Role for Perl 5 | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =head1 SYNOPSIS | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | package Example; | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | use Venus::Class; | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | with 'Venus::Role::Throwable'; | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | package main; | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | my $example = Example->new; | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # $example->throw; | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =head1 DESCRIPTION | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | This package modifies the consuming package and provides a mechanism for | ||||||||||||||||||||
| 64 | throwing context-aware errors (exceptions). | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =head1 METHODS | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | This package provides the following methods: | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =head2 throw | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | throw(Maybe[Str] $package) (Throw) | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | The throw method builds a L<Venus::Throw> object, which can raise errors | ||||||||||||||||||||
| 79 | (exceptions). | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | I<Since C<0.01>> | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =over 4 | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =item throw example 1 | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | package main; | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | my $example = Example->new; | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | my $throw = $example->throw; | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | # bless({ "package" => "Example::Error", ..., }, "Venus::Throw") | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | # $throw->error; | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =back | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =cut | ||||||||||||||||||||