| 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')
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')
| |||||||||||||||||||||
| 27 | 0 | ▶ | print " = reading $tmpl_path\n" if $args->{verbose}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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')
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')
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 42 | # ... on disk | ||||||||||||||||||||
| 43 | 0 | $output->name($fullpath); | |||||||||||||||||||
| 44 | 0 | ▶ | print " + writing ", $output->fullpath, $/ if $args->{verbose}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||