blib/lib/RackMan/Format/Generic.pm

filter: Statementstmt 43.2% 16 / 37 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 36.6% 22 / 60 CC 6 SCAR 31.5
CC
6
Cov
33%
write
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 23.4
« blib/lib/RackMan/Format/Bacula.pm ↑ Summary blib/lib/RackMan/Format/Kickstart.pm »
1 package RackMan::Format::Generic;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use RackMan::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use RackMan::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 CONFIG_SECTION => "format:generic",
11 1 };
12  
13  
14 #
15 # write()
16 # -----
17 0 ▶sub write {
Subroutine write: not called CC=6 SCAR=37.4
Pod documented
18 0 my ($class, $args) = @_;
19  
20 0 my $rackdev = $args->{rackdev};
21 0 my $rackman = $args->{rackman};
22 0 my $output = RackMan::File->new;
23  
24 # load and populate the template
25 my $tmpl_path = $rackman->options->{template}
26 0 ▶ || $rackman->config->val(CONFIG_SECTION, "template");
Condition0%0/3
$rackman->options->{'template'} || $rackman->config->val('format:generic', 'template')
l!l&&r!l&&!r
000
MC/DC0%0/2
$rackman->options->{'template'} || $rackman->config->val('format:generic', 'template')
$rackman->options->{'template'} $rackman->config->val('format:generic', 'template')
Truth table0%0/3
A || B
A= $rackman->options->{'template'}B= $rackman->config->val('format:generic', 'template')
ABresult
1X1
011
000
27 0 ▶ print " = reading $tmpl_path\n" if $args->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"verbose"} 0 0 0
28 0 my $tmpl = RackMan::Template->new(filename => $tmpl_path);
29 0 $tmpl->populate_from($rackdev, $rackman);
30  
31 # generate the output file
32 0 $output->add_content($tmpl->output);
33  
34 # get the output path. the little juggle is to allow %name% expansion
35 my $fullpath = $rackman->options->{output}
36 0 ▶ || $rackman->config->val(CONFIG_SECTION, "path");
Condition0%0/3
$rackman->options->{'output'} || $rackman->config->val('format:generic', 'path')
l!l&&r!l&&!r
000
MC/DC0%0/2
$rackman->options->{'output'} || $rackman->config->val('format:generic', 'path')
$rackman->options->{'output'} $rackman->config->val('format:generic', 'path')
Truth table0%0/3
A || B
A= $rackman->options->{'output'}B= $rackman->config->val('format:generic', 'path')
ABresult
1X1
011
000
37 0 $rackman->config->newval(CONFIG_SECTION, "path", $fullpath);
38 0 $fullpath = $rackman->config->val(CONFIG_SECTION, "path");
39  
40 # write the output file
41 0 ▶ if ($fullpath) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fullpath) { } 0 0 0
42 # ... on disk
43 0 $output->name($fullpath);
44 0 ▶ print " + writing ", $output->fullpath, $/ if $args->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"verbose"} 0 0 0
45 0 my $scm = $rackman->get_scm({ path => $output->path });
46 0 $scm->update;
47 0 $output->write;
48 0 $scm->add($output->name);
49 0 $scm->commit($output->name, "generated by $class / $::PROGRAM v$::VERSION");
50 }
51 else {
52 # ... on screen
53 0 print $output->content;
54 }
55 }
56  
57  
58 1 __PACKAGE__
59  
60 __END__
« blib/lib/RackMan/Format/Bacula.pm ↑ Summary blib/lib/RackMan/Format/Kickstart.pm »