File Coverage

blib/lib/WWW/Shopify/Exception.pm
Criterion Covered Total %
statement 24 40 60.0
branch 0 8 0.0
condition 0 6 0.0
subroutine 8 18 44.4
pod 0 5 0.0
total 32 77 41.5


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3 1     1   3 use strict;
  1         1  
  1         21  
4 1     1   3 use warnings;
  1         1  
  1         17  
5 1     1   408 use Devel::StackTrace;
  1         2175  
  1         111  
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   4 };
  1         1  
  1         12  
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   514 use parent 'WWW::Shopify::Exception';
  1         198  
  1         4  
33 0     0     sub default_error { return "Call limit reached."; }
34              
35             package WWW::Shopify::Exception::InvalidKey;
36 1     1   58 use parent 'WWW::Shopify::Exception';
  1         1  
  1         3  
37 0     0     sub default_error { return "Invalid API key."; }
38              
39             package WWW::Shopify::Exception::NotFound;
40 1     1   47 use parent 'WWW::Shopify::Exception';
  1         1  
  1         4  
41 0     0     sub default_error { return "Asset not found."; }
42              
43             package WWW::Shopify::Exception::DBError;
44 1     1   46 use parent 'WWW::Shopify::Exception';
  1         1  
  1         2  
45 0     0     sub default_error { return "Database error."; }
46              
47             1;