File Coverage

blib/lib/Storage/Abstract/X.pm
Criterion Covered Total %
statement 41 41 100.0
branch 4 6 66.6
condition n/a
subroutine 11 11 100.0
pod 2 2 100.0
total 58 60 96.6


line stmt bran cond sub pod time code
1             package Storage::Abstract::X;
2             $Storage::Abstract::X::VERSION = '0.008';
3 11     11   133 use v5.14;
  11         51  
4 11     11   63 use warnings;
  11         30  
  11         600  
5              
6 11     11   56 use Mooish::Base -standard;
  11         20  
  11         101  
7              
8             use overload
9 11         126 q{""} => "as_string",
10 11     11   140564 fallback => 1;
  11         26  
11              
12             has param 'path' => (
13             isa => Maybe [Str],
14             );
15              
16             has param 'message' => (
17             isa => Str,
18             writer => -hidden,
19             );
20              
21             has field 'caller' => (
22             default => sub {
23             for my $call_level (1 .. 10) {
24             my @data = caller $call_level;
25             return \@data
26             if $data[1] !~ /^\(eval/ && $data[0] !~ /^Storage::Abstract/;
27             }
28             return undef;
29             },
30             );
31              
32             our $path_context;
33              
34             sub raise
35             {
36 28     28 1 154 my ($self, $error) = @_;
37              
38 28 50       79 if (defined $error) {
39 28         579 $self = $self->new(message => $error, path => $path_context);
40             }
41              
42 28         1570 die $self;
43             }
44              
45             sub as_string
46             {
47 40     40 1 11097 my ($self) = @_;
48              
49 40         166 my $raised = $self->message;
50 40         230 $raised =~ s/\s+\z//;
51              
52 40 100       179 if (my $path = $self->path) {
53 38         105 $raised .= " for path '$path'";
54             }
55              
56 40 50       150 if (my $caller = $self->caller) {
57 40         114 $raised .= ' (raised at ' . $caller->[1] . ', line ' . $caller->[2] . ')';
58             }
59              
60 40         88 my $class = ref $self;
61 40         69 my $pkg = __PACKAGE__;
62 40         378 $class =~ s/${pkg}:://;
63              
64 40         224 return "Storage::Abstract exception: [$class] $raised";
65             }
66              
67             ## SUBCLASSES
68              
69             package Storage::Abstract::X::NotFound {
70             $Storage::Abstract::X::NotFound::VERSION = '0.008';
71 11     11   6981 use parent -norequire, 'Storage::Abstract::X';
  11         266  
  11         104  
72             }
73              
74             package Storage::Abstract::X::Readonly {
75             $Storage::Abstract::X::Readonly::VERSION = '0.008';
76 11     11   908 use parent -norequire, 'Storage::Abstract::X';
  11         20  
  11         47  
77             }
78              
79             package Storage::Abstract::X::PathError {
80             $Storage::Abstract::X::PathError::VERSION = '0.008';
81 11     11   791 use parent -norequire, 'Storage::Abstract::X';
  11         20  
  11         46  
82             }
83              
84             package Storage::Abstract::X::HandleError {
85             $Storage::Abstract::X::HandleError::VERSION = '0.008';
86 11     11   787 use parent -norequire, 'Storage::Abstract::X';
  11         26  
  11         61  
87             }
88              
89             package Storage::Abstract::X::StorageError {
90             $Storage::Abstract::X::StorageError::VERSION = '0.008';
91 11     11   707 use parent -norequire, 'Storage::Abstract::X';
  11         19  
  11         37  
92             }
93              
94             1;
95              
96             __END__