lib/Rapi/Blog/PreAuth/Actor/Error.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 119 CC 3 SCAR 12.8
CC
3
Cov
0%
throw
12.0
class_name
2.0
BUILD
2.0
CRAP 3.6
1 package Rapi::Blog::PreAuth::Actor::Error;
2 use strict;
3 use warnings;
4  
5 # ABSTRACT: Base error class for preauth Actors
6  
7 use Moo;
8 extends 'Rapi::Blog::PreAuth::Actor';
9  
10 use Types::Standard qw(:all);
11  
12 use RapidApp::Util ':all';
13 use Rapi::Blog::Util;
14 use Scalar::Util 'blessed';
15  
16 # just to override:
17 has 'PreauthAction', is => 'ro', init_arg => undef, default => sub {undef};
18 has 'ctx', is => 'ro', required => 0;
19  
20 has 'title', is => 'ro', isa => Maybe[Str], default => sub{undef};
21 has 'subtitle', is => 'ro', isa => Maybe[Str], default => sub{undef};
22  
23 sub class_name {
24 my $self = shift;
25 blessed $self || $self;
26 }
27  
28 sub BUILD {
29 my $self = shift;
30 $self->info or $self->info( $self->_default_error_info )
31 }
32  
33 use overload '""' => 'stringify';
34  
35 sub stringify {
36 my $self = shift;
37 $self->info || $self->_default_error_info
38 }
39  
40 sub _default_error_info {
41 my $self = shift;
42 my $type = $self->error_type || $self->class_name;
43 "Actor: unspecified '$type' error\n"
44 }
45  
46  
47 sub is_error { 1 }
48  
49 sub error_type {
50 my $self = shift;
51 my $class = $self->class_name;
52 (split(/Rapi::Blog::PreAuth::Actor::Error::/,$class,2))[1];
53 }
54  
55 sub throw {
56 my ($self,@args) = @_;
57
58 # first argument can be a scalar/string (used as default 'info' option):
59 my $msg = (defined $args[0] && ! ref($args[0])) ? (shift @args) : undef;
60
61 # and still allow additional arguments as key/vals:
62 my %opts = (ref($_[0]) eq 'HASH') ? %{ $_[0] } : @_; # <-- arg as hash or hashref
63
64 $opts{info} ||= $msg || $self->_default_error_info;
65
66 die $self->new(\%opts)
67 }
68  
69  
70 sub execute { die (shift) }
71 sub call_execute { die (shift) }
72  
73  
74 1;
75  
76  
77 __END__