WAAE.pm

filter: Statementstmt 17.6% 12 / 68 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 37.5% 3 / 8 Podpod 100% 4 / 4 totaltotal 15.8% 19 / 120 CC 21 SCAR 42.2
CC
21
Cov
12%
send_event
132.0
new
56.0
job_list
12.0
CRAP 68.1
↑ Summary WAAE/Job.pm »
1 #
2 # CA::WAAE - Perl Interface to CA's AutoSys job control.
3 #
4 # Original CA::AutoSys code:
5 # Copyright (c) 2007 Sinisa Susnjar <sini@cpan.org>
6 # See LICENSE for terms of distribution.
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #
22  
23 package CA::WAAE;
24  
25 1 require CA::WAAE::Job;
26  
27 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 our $VERSION = '0.03';
32  
33 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
34 0 my $self = {};
35 0 my $class = shift();
36  
37 0 my %args = @_;
38 0 for my $attr (qw(dsn user password dbh db_type table_prefix schema)) {
39 0 $self->{$attr} = $args{$attr};
40 }
41  
42 0 ▶ if ( !$self->{dbh} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dbh"}) 0 0 0
43 0 ▶ die "no dbh/dsn given in new()" if !$self->{dsn};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dsn"} 0 0 0
44 $self->{dbh}
45 = DBI->connect( $self->{dsn}, $self->{user}, $self->{password},
46 0 { PrintError => 0, RaiseError => 1 } );
47 }
48  
49 0 my $db_type = $self->{dbh}{Driver}{Name};
50 0 ▶ if ( $db_type eq 'Oracle' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_type eq "Oracle") 0 0 0
51  
52 # Default and untaint schema/table_prefix
53 0 ▶ $self->{schema} ||= 'aedbadmin';
Condition0%0/2
$self->{"schema"} ||= "aedbadmin"
l!l
00
MC/DC0%0/1
$self->{"schema"} ||= "aedbadmin"
$self->{"schema"}
Truth table0%0/2
A
A= $self->{"schema"}
Aresult
11
00
54 0 $self->{schema} =~ /(\w+)/;
55 0 $self->{schema} = $1;
56  
57 0 ▶ $self->{table_prefix} ||= 'ujo_';
Condition0%0/2
$self->{"table_prefix"} ||= "ujo_"
l!l
00
MC/DC0%0/1
$self->{"table_prefix"} ||= "ujo_"
$self->{"table_prefix"}
Truth table0%0/2
A
A= $self->{"table_prefix"}
Aresult
11
00
58 0 $self->{table_prefix} =~ /([\w.]+)/;
59 0 $self->{table_prefix} = $1;
60  
61 0 $self->{dbh}->do("alter session set current_schema=$self->{schema}");
62 }
63  
64 0 bless $self, $class;
65 0 return $self;
66 } # new()
67  
68 0 ▶sub _query {
Subroutine _query: not called CC=2 SCAR=17.9
69 0 my $self = shift;
70 0 ▶ my $prefix = $self->{table_prefix} || '';
Condition0%0/2
$self->{'table_prefix'} || ''
l!l
00
MC/DC0%0/1
$self->{'table_prefix'} || ''
$self->{'table_prefix'}
Truth table0%0/2
A
A= $self->{'table_prefix'}
Aresult
11
00
71 0 my $query = <<SQL;
72 select j.*, s.*, j2.job_name as box_name, m.name job_type_name
73 from ${prefix}job j join ${prefix}job_status s
74 on j.joid = s.joid
75 left outer join ${prefix}job j2
76 on j.box_joid = j2.joid
77 left outer join ${prefix}meta_types m
78 on j.job_type = m.type_id and m.sub_type = 'STRINGS'
79 SQL
80 0 return $query;
81 } # _query()
82  
83 0 ▶sub find_jobs {
Subroutine find_jobs: not called CC=2 SCAR=17.9
Pod documented
84 0 my $self = shift();
85 0 my $job_name = shift();
86  
87 0 $job_name =~ s/\*/%/g;
88 0 ▶ my $op = ( $job_name =~ /[%?]/ ) ? 'like' : '=';
Branch: 1 branch
BranchTrueFalseTotal
$job_name =~ /[%?]/ ? : 0 0 0
89  
90 0 my $query = $self->_query() . <<SQL;
91 where j.job_name $op ?
92 order by j.joid
93 SQL
94 0 my $sth = $self->{dbh}->prepare($query);
95 0 $sth->execute($job_name);
96  
97 return CA::WAAE::JobList->new(
98 parent => $self->{parent},
99 database_handle => $self->{dbh},
100 statement_handle => $sth,
101 table_prefix => $self->{table_prefix},
102 0 );
103  
104 } # find_jobs()
105  
106 0 ▶sub job_list {
Subroutine job_list: not called CC=3 SCAR=24.8
Pod documented
107 0 my $self = shift;
108 0 my $h = $self->find_jobs(@_);
109 0 my @list;
110 0 ▶ while ( my $job = $h->next_job() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $job = $h->next_job) 0 0 0
111 0 push @list, $job;
112 }
113 0 ▶ return wantarray ? @list : \@list;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
114 }
115  
116 0 ▶sub send_event {
Subroutine send_event: not called CC=11 SCAR=48.8
Pod documented
117 0 my $self = shift();
118 0 my ( $job_name, $event, $status, $event_time );
119 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
120 0 my %args = @_;
121 0 ▶ $job_name = $args{job_name} ? $args{job_name} : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'job_name'} ? : 0 0 0
122 0 ▶ $event = $args{event} ? $args{event} : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'event'} ? : 0 0 0
123 0 ▶ $status = $args{status} ? $args{status} : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'status'} ? : 0 0 0
124 0 ▶ $event_time = $args{event_time} ? $args{event_time} : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'event_time'} ? : 0 0 0
125 }
126  
127 0 my $dbh = $self->{dbh};
128 0 my $db_type = $self->{db_type};
129  
130 0 $_ = $dbh->quote($_) for $job_name, $event, $status, $event_time;
131 0 ▶ my $prefix = $self->{table_prefix} || '';
Condition0%0/2
$self->{'table_prefix'} || ''
l!l
00
MC/DC0%0/1
$self->{'table_prefix'} || ''
$self->{'table_prefix'}
Truth table0%0/2
A
A= $self->{'table_prefix'}
Aresult
11
00
132 0 ▶ my $sql
Branch: 1 branch
BranchTrueFalseTotal
$db_type eq 'Oracle' ? : 0 0 0
133 = ( $db_type eq 'Oracle' )
134 ? "BEGIN :rtn := ${prefix}sendevent( $event, $job_name, $status, '', $event_time ); END;"
135 : qq( exec sendevent $event, $job_name, $status, '', $event_time, '' );
136 0 my $sth = $dbh->prepare($sql);
137  
138 0 my $rc;
139 0 ▶ $sth->bind_param_inout( ':rtn', \$rc, 128 ) if $db_type eq 'Oracle';
Branch: 1 branch
BranchTrueFalseTotal
if $db_type eq "Oracle" 0 0 0
140 0 $sth->execute();
141 0 ▶ ($rc) = $sth->fetchrow_array() if $db_type ne 'Oracle';
Branch: 1 branch
BranchTrueFalseTotal
if $db_type ne "Oracle" 0 0 0
142  
143 0 return $rc;
144 } # send_event()
145  
146 1 1;
147 __END__
↑ Summary WAAE/Job.pm »