JavaScript/Exception.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 49 CC 2 SCAR 9.4
CC
2
Cov
0%
to_string
6.0
new
2.0
name
2.0
CRAP 2.6
1 package Mac::Safari::JavaScript::Exception;
2  
3 # This isn't a problem, all Macs have at least 5.8
4 use 5.008;
5  
6 use strict;
7 use warnings;
8  
9 our $VERSION = "0.04";
10  
11 # overload stringification, but also overload boolean evalulation so
12 # if the string form of this exception is the empty string, this still
13 # has a true value
14 use overload '""' => "to_string", bool => sub { 1 }, fallback => 1;
15  
16 # this is super lightweight. I'd feel more comfortable writing this in moose,
17 # as that would give us nice error checking, but that's too much dependancy
18 # for such a simple class
19  
20 sub new {
21 my $class = shift;
22 return bless { @_ }, $class;
23 }
24  
25 sub name { return $_[0]->{name} }
26 sub line { return $_[0]->{line} }
27 sub sourceId { return $_[0]->{sourceId} } ## no critic (ProhibitMixedCaseSubs)
28 sub message { return $_[0]->{message} }
29 sub error { return $_[0]->{error} }
30 sub expressionBeginOffset ## no critic (ProhibitMixedCaseSubs)
31 { return $_[0]->{expressionBeginOffset} }
32 sub expressionEndOffset ## no critic (ProhibitMixedCaseSubs)
33 { return $_[0]->{expressionEndOffset} }
34  
35 sub to_string { return exists $_[0]->{message} ? $_[0]->{message} : $_[0]->{error}; }
36  
37 1;
38  
39 __END__