ETLp/Exception.pm untested

filter: Statementstmt 0.0% 0 / 7 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod n/a totaltotal 0.0% 0 / 9 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package ETLp::Exception;
2  
3 use MooseX::Declare;
4  
5 =head1 NAME
6  
7 ETLp::Exception - ETLp Exception Class
8  
9 =head1 SYNOPSIS
10  
11 use MooseX::Declare
12 class My::ETL {
13 use ETLp::Exception;
14 use Try::Tiny
15
16 method do_stuff {
17 unless ($self->continue) {
18 ETLpException->throw(error => "Can't continue");
19 }
20 }
21
22 method call_do_stuff {
23 try {
24 do_stuff
25 } catch {
26 print "Error $_";
27 $_->rethrow;
28 }
29 }
30 }
31
32 =head1 DESCRIPTION
33  
34 ETLP::Exception provides ETLpException, an Exception:Class
35 object. Because it can be stringified, it can simply be printed
36 or inserted into a database.
37  
38 The exception can also be sub-classed if required:
39  
40 class My::ETL::CSV {
41 use Exception::Class (
42 ETLpExceptionCSV => {
43 isa => 'ETLpException',
44 fields => [qw/error_code short_name/]
45 }
46 );
47
48 method load_csv (Str $filename) {
49 $self->insert_into_db($filename) || ETLpExceptionCSV->throw(
50 error => 'Unable to insert into DB:$!',
51 error_code => 29,
52 short_name => 'insertion error',
53 );
54 }
55 }
56
57 # In some different class
58
59 my $loader = My::ETL::CSV->new()
60
61 try {
62 $loader->load_csv
63 } catch {
64 my $error = $_;
65 $self->logger->error($error->error_code . ':' . $error->error);
66 $error->rethrow;
67 }
68
69 =cut
70  
71 class ETLp::Exception {
72 use Exception::Class (
73 'ETLpException'
74 );
75 }
76  
77 =head1 LICENSE AND COPYRIGHT
78  
79 Copyright 2010 Redbone Systems Ltd
80  
81 This program is free software; you can redistribute it and/or modify it
82 under the terms of either: the GNU General Public License as published
83 by the Free Software Foundation; or the Artistic License.
84  
85 The terms are in the LICENSE file that accompanies this application