| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 4 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 5 | 1 |  |  | 1 |  | 799 | use Devel::StackTrace; | 
|  | 1 |  |  |  |  | 3641 |  | 
|  | 1 |  |  |  |  | 186 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | # Basic WWW::Shopify exception class; | 
| 8 |  |  |  |  |  |  | package WWW::Shopify::Exception; | 
| 9 |  |  |  |  |  |  | use overload | 
| 10 |  |  |  |  |  |  | 'fallback' => 1, | 
| 11 |  |  |  |  |  |  | '""' => sub { | 
| 12 | 0 |  |  | 0 |  | 0 | my ($exception) = @_; | 
| 13 | 0 | 0 | 0 |  |  | 0 | if ($exception->error && ref($exception->error) && ref($exception->error) eq "HTTP::Response") { | 
|  |  |  | 0 |  |  |  |  | 
| 14 | 0 |  |  |  |  | 0 | my $code = $exception->error->code; | 
| 15 | 0 | 0 |  |  |  | 0 | my $message = $exception->error->message ? $exception->error->message : "N/A"; | 
| 16 | 0 | 0 |  |  |  | 0 | my $content = $exception->error->decoded_content ? $exception->error->decoded_content : "N/A"; | 
| 17 | 0 |  |  |  |  | 0 | return "Error: HTTP $code : $message\n$content\n" . $exception->stack; | 
| 18 |  |  |  |  |  |  | } | 
| 19 | 0 |  |  |  |  | 0 | return "Error: " . $exception->error . "\n" . $exception->stack; | 
| 20 | 1 |  |  | 1 |  | 7 | }; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 8 |  | 
| 21 |  |  |  |  |  |  | # Generic constructor; class is blessed with the package that new specifies, and contains a hash specified inside the parentheses of a new call. | 
| 22 |  |  |  |  |  |  | # Example: new WWW::Shopify::Exception('try' => 'catch'); $_[0] is 'WWW::Shopify::Exception', $_[1] is {'try' => 'catch'}. | 
| 23 |  |  |  |  |  |  | # The object will be of type WWW::Shopify::Exception, and have the contents of {'try' => 'catch'}. | 
| 24 | 0 | 0 |  | 0 | 0 |  | sub new { return bless {'error' => $_[1] ? $_[1] : $_[0]->default_error, 'stack' => Devel::StackTrace->new, extra => $_[2]}, $_[0]; } | 
| 25 | 0 |  |  | 0 | 0 |  | sub extra { return $_[0]->{extra}; } | 
| 26 | 0 |  |  | 0 | 0 |  | sub error { return $_[0]->{error}; } | 
| 27 | 0 |  |  | 0 | 0 |  | sub stack { return $_[0]->{stack}; } | 
| 28 | 0 |  |  | 0 | 0 |  | sub default_error { return "Unknown exception occured."; } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | # Thrown when a URL request exceeds the Shopify API call limit. | 
| 31 |  |  |  |  |  |  | package WWW::Shopify::Exception::CallLimit; | 
| 32 | 1 |  |  | 1 |  | 948 | use parent 'WWW::Shopify::Exception'; | 
|  | 1 |  |  |  |  | 367 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 33 | 0 |  |  | 0 |  |  | sub default_error { return "Call limit reached."; } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | package WWW::Shopify::Exception::InvalidKey; | 
| 36 | 1 |  |  | 1 |  | 83 | use parent 'WWW::Shopify::Exception'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 3 |  | 
| 37 | 0 |  |  | 0 |  |  | sub default_error { return "Invalid API key."; } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | package WWW::Shopify::Exception::NotFound; | 
| 40 | 1 |  |  | 1 |  | 66 | use parent 'WWW::Shopify::Exception'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 41 | 0 |  |  | 0 |  |  | sub default_error { return "Asset not found."; } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | package WWW::Shopify::Exception::DBError; | 
| 44 | 1 |  |  | 1 |  | 66 | use parent 'WWW::Shopify::Exception'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 3 |  | 
| 45 | 0 |  |  | 0 |  |  | sub default_error { return "Database error."; } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | 1; |