| 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__ |