ETLp/Plugin/Iterative/PLSQL.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 84 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package ETLp::Plugin::Iterative::PLSQL;
2  
3 use MooseX::Declare;
4  
5 =head1 NAME
6  
7 ETLp::Plugin::Iterative::PLSQL - Plugin for calling Oracle procedures
8  
9 =head1 METHODS
10  
11 =head2 type
12  
13 Registers the plugin type.
14  
15 =head2 run
16  
17 Executes the pipeline
18  
19 =cut
20  
21 class ETLp::Plugin::Iterative::PLSQL extends ETLp::Plugin {
22
23 use DBI;
24 use Data::Dumper;
25 use Try::Tiny;
26  
27 method _parse_params (HashRef $config, ArrayRef $params, Str $filename) {
28 my $parsed_params;
29
30 return $parsed_params;
31 }
32  
33 sub type {
34 return 'plsql';
35 }
36
37 method run (Str $filename?) {
38 my $config = $self->config->{config};
39 my $item = $self->item;
40 my $params = $item->{parameters};
41 my $sql = "BEGIN\n" . $item->{call};
42 my $message;
43
44 $params = [$params]
45 unless (ref($params) eq 'ARRAY' || !defined($item->{parameters}));
46 my $aud_file_process = $self->audit->item->file_process;
47
48 $self->logger->debug(Dumper($params));
49
50 # If we have any parameters then add them to the construction list
51 if ($params) {
52 $sql .= '(';
53 my $param_counter = 0;
54 foreach my $param (@$params) {
55 unless($param->{name} && $param->{value}) {
56 ETLpException->throw(
57 error => 'parameter requires a name and a value'
58 );
59 }
60
61 if ($param_counter++ > 0) {
62 $sql .= ",\n\t";
63 } else {
64 $sql .= "\n\t"
65 }
66 $sql .= $param->{name}.' => :'.$param->{name};
67 }
68 $sql .= ");\nEND;";
69 } else {
70 $sql .= ";\nEND;";
71 }
72
73 $self->logger->debug("pl/sql block:\n$sql");
74
75 my $sth = $self->dbh->prepare($sql);
76
77 if($params) {
78 foreach my $param (@$params) {
79 if ($param->{value} eq '%message%') {
80 $sth->bind_param_inout(':'.$param->{name}, \$message,
81 4000);
82 } else {
83 $sth->bind_param(':'. $param->{name}, $param->{value});
84 }
85 }
86 }
87
88 $sth->execute || ETLpException->throw(error => DBI::errstr);
89
90 if ($message) {
91 $self->audit->item->update_message($message);
92 };
93
94 return $filename;
95 }
96 }
97  
98 =head1 LICENSE AND COPYRIGHT
99  
100 Copyright 2010 Redbone Systems Ltd
101  
102 This program is free software; you can redistribute it and/or modify it
103 under the terms of either: the GNU General Public License as published
104 by the Free Software Foundation; or the Artistic License.
105  
106 The terms are in the LICENSE file that accompanies this application