AutoSys.pm

filter: Statementstmt 40.9% 25 / 61 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 3 / 3 totaltotal 34.3% 34 / 99 CC 14 SCAR 38.8
CC
14
Cov
29%
new
90.0
send_event
42.0
find_jobs
2.0
CRAP 48.6
↑ Summary AutoSys/Status.pm »
1 #
2 # $Id: AutoSys.pm 68 2008-02-11 10:50:27Z sini $
3 #
4 # CA::AutoSys - Perl Interface to CA's AutoSys job control.
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::AutoSys;
24  
25 1 require CA::AutoSys::Job;
26 1 require CA::AutoSys::Status;
27  
28 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 1 $VERSION = '1.05';
35  
36 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use vars qw(@ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 @ISA = qw(Exporter);
39 1 @EXPORT = qw(&new);
40  
41 1 our $errstr;
42  
43 0 ▶sub new {
Subroutine new: not called CC=9 SCAR=45.0
Pod documented
44 0 my $self = {};
45 0 my $class = shift();
46  
47 0 $errstr = '';
48  
49 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
50 0 my %args = @_;
51 0 ▶ $self->{dsn} = $args{dsn} ? $args{dsn} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args{'dsn'} ? : 0 0 0
52 0 ▶ $self->{server} = $args{server} ? $args{server} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args{'server'} ? : 0 0 0
53 0 ▶ $self->{user} = $args{user} ? $args{user} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args{'user'} ? : 0 0 0
54 0 ▶ $self->{password} = $args{password} ? $args{password} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$args{'password'} ? : 0 0 0
55 }
56  
57 0 ▶ if (!defined($self->{dsn})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dsn"}) 0 0 0
58 0 ▶ if (!defined($self->{server})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"server"}) 0 0 0
59 0 $errstr = "no dsn given in new()";
60 0 return undef;
61 }
62 # Default to Sybase when no dsn was given...
63 0 $self->{dsn} = "dbi:Sybase:server=$self->{server}";
64 }
65 0 $self->{dbh} = DBI->connect($self->{dsn}, $self->{user}, $self->{password});
66 0 ▶ if (!$self->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dbh"}) 0 0 0
67 0 $errstr = "can't connect to dsn ".$self->{dsn}.": ".$DBI::errstr;
68 0 return undef;
69 }
70  
71 0 bless($self);
72 0 return $self;
73 } # new()
74  
75 0 ▶sub find_jobs {
Subroutine find_jobs: not called CC=1 SCAR=6.9
Pod documented
76 0 my $self = shift();
77 0 my $job_name = shift();
78 0 my $job = CA::AutoSys::Job->new(parent => $self, database_handle => $self->{dbh});
79 0 return $job->find_jobs($job_name);
80 } # find_jobs()
81  
82 0 ▶sub send_event {
Subroutine send_event: not called CC=6 SCAR=37.4
Pod documented
83 0 my $self = shift();
84 0 my ($job_name, $event, $status, $event_time);
85 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
86 0 my %args = @_;
87 0 ▶ $job_name = $args{job_name} ? $args{job_name} : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'job_name'} ? : 0 0 0
88 0 ▶ $event = $args{event} ? $args{event} : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'event'} ? : 0 0 0
89 0 ▶ $status = $args{status} ? $args{status} : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'status'} ? : 0 0 0
90 0 ▶ $event_time = $args{event_time} ? $args{event_time} : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'event_time'} ? : 0 0 0
91 }
92  
93 0 my $sth = $self->{dbh}->prepare(qq{
94 exec sendevent '$event', '$job_name', '$status', '', '$event_time', ''
95 });
96  
97 0 $sth->execute();
98  
99 0 my ($rc) = $sth->fetchrow_array();
100 0 return $rc;
101 } # send_event()
102  
103 1 1;
104 __END__
↑ Summary AutoSys/Status.pm »