| 1 | package NCustom; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict qw(vars); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use vars qw(%Config $Transaction $req); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use File::Compare; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use File::Find; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use File::Path; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use File::Temp qw(tempfile tempdir); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use FindBin qw($Bin); #this finds the dir of the src of $0 | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Text::ParseWords; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Socket; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Symbol qw(delete_package); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 18 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 18 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 'all' => [ qw( &transaction &save_files &initialise &overwrite_file &append_file &prepend_file &edit_file &undo_files &required_packages $req &apt_fix &ncustom &blat_myconfig &config_edit) ] | ||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | our @EXPORT = qw( ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | our $VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # /////////////////////////////////////////////////////////////////// | ||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | #<< PP: POD Prefix <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | NCustom - Perl extension for customising system configurations. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | NCUSTOM_SCRIPT | ||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | use NCustom; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # do stuff in your script using NCustom routines | ||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | KICKSTART POST SECTION | ||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # install package management tool that is used in NCUSTOM_SCRIPT | ||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | rpm -i http://install/install/rpm/apt-0.5.5cnc6-fr1.i386.rpm ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | echo 'rpm http://install/ install/rh90_apt os extras' > /etc/apt/sources.list; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | apt-get update ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # install and use NCustom | ||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | apt-get -q -y install perl-NCustom ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ncustom -i ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ncustom -c src_fqdn=install.example.com ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ncustom -n NCUSTOM_SCRIPT | ||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ncustom -n smb_ldap_pdc-0.4-rh90.ncus ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | =head1 ABSTRACT | ||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | NCustom provides some file editting routines and some package management hooks to assit in system configuration. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | File editting: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | The file editing routines include features such as transactions, and undo by transaction. The original files are archived within a directory tree structure. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | Package management: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | You may specify packages (and minumum/maximum/exact versions) that you require to be installed, and a routine to be called if they are not installed. Your routine may use simple "rpm" commands (or whatever you want), or you may use the provided routine that uses "apt". In-built support for other package management tools is on the todo list. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | System configuration: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | A commandline interface provides for initialisation, configuration, and invocation (including invocation across the network). This enables NCustom to be used from the post section of Kickstart script. It may also be used stand alone on an already built system. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | If system configuration tweaking is minor, then scripts (even in the post section of a kickstart configuration) may be more useful. If the system configuration tweaking is related to only one rpm, then re-rolling the rpm with a new post section may be more useful. If there are several packages that need inter-related configuration (eg building a Samba, PDC, LDAP server), then NCustom may improve the speed of development of automated system configuration. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | File editting: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Files are saved into a directory structure within the users home directory. This location may be configured. A file will be saved within a directory structure named after the current transaction name, and also under the "all" directory. Because of this "all" changes, or only changes relating to a "transaciton" may be reversed. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | Package management: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | When a package requirement is not met, a routine that you may provide shall be called. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | System configuration: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | =head2 EXPORT | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | None by default. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | =head2 API | ||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # /////////////////////////////////////////////////////////////////// | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | #<< FF: Functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # Inline testing setup and general tests | ||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | =begin testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | use File::Compare ; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | use File::Copy ; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | ▶ | use File::Path ; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | use File::Spec ; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | use vars qw($output $input); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # test setup | ||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $output = File::Spec->rel2abs("./t/embedded-NCustom.o"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $input = File::Spec->rel2abs("./t/embedded-NCustom.i"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | ok( -d $input) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | || diag("TEST:<test setup> requires the data input directory be present"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | -d $input || die; # as if we have that wrong we could clobber allsorts | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | rmtree $output; | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | mkpath $output; | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | $ENV{HOME} = $output ; # lets be non-intrusive | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | use_ok( "NCustom", qw(:all) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | || diag("TEST:<NCustom> is a package"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 16 | ▶ | sub test_reset { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_reset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | #Test::Inline doesnt execute test blocks in order | ||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | #it does all basic tests first (seemingly in declaration order), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | #then examples tests (seemingly in declaration order). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | #hmmm.. test_rest can erase "why test failed" data | ||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | rmtree $output; | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | mkpath $output; | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 16 | &NCustom::constructor(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 16 | transaction("tx1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 16 | system("cp -r $input/subject/* $output"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 19 | ▶ | sub output { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 16 | ▶ | $_STDOUT_ && diag($_STDOUT_); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 16 | ▶ | $_STDERR_ && diag($_STDERR_); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | =end testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # load_config | ||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | =begin testing | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | NCustom::load_config(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | is($NCustom::Config{'test_data1'}, "global_value") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | || diag("TEST:<load_config> sets variables from global conf file 1/3"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | ▶ | is($NCustom::Config{'test_data2'}, "global_value") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | || diag("TEST:<load_config> sets variables from global conf file 2/3"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | is($NCustom::Config{'save_dir'}, "$output/.ncustom/save",) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | || diag("TEST:<load_config> sets variables from global conf file 3/3"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | mkpath "$output/.ncustom/NCustom" ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | copy("$input/MyConfig.pm", "$output/.ncustom/NCustom"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | NCustom::load_config(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | is($NCustom::Config{'test_data1'}, "global_value") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | TEST:<load_config> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | TEST: - will use a local conf file if present | ||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | TEST: - will still inheirit settings from global conf file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | ▶ | is($NCustom::Config{'test_data2'}, "local_value") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | TEST:<load_config> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | TEST: - local conf file settings will override global conf file settings | ||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | my $subref = $NCustom::Config{'get_url'}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | my $target_url = "dummy_url"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | my $target_dir = "dummy_dir"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | &$subref($target_url, $target_dir); | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | open(STUBSLOG, "< $output/stubs.log"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | my @lines = <STUBSLOG>; | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | close(STUBSLOG); | |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | ok( grep( /get_url ${target_url} ${target_dir}/, @lines) > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | || diag("TEST:<load_config> override works for get_url handler"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | TODO: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | local $TODO = "Unload and reload modules, eg Symbol::delete_package."; | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | #testing can reset / toggle | ||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | #Q: is this useful outside of testing context ? | ||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | #A: no | ||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | rmtree "$output/.ncustom/NCustom" ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | NCustom::load_config(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | is($NCustom::Config{'test_data1'}, "global_value") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | || diag("TEST:<load_config> is re-runnable and resets configuration 1/2"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | is($NCustom::Config{'test_data2'}, "global_value") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | || diag("TEST:<load_config> is re-runnable and resets configuration 2/2"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | =end testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 21 | ▶ | sub load_config{ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_config: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | delete_package("NCustom::Config");# if exists $NCustom::{'Config::'}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 19 | delete_package("NCustom::MyConfig");# if exists $NCustom::{'MyConfig::'}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 21 | require NCustom::Config ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 21 | unshift @INC, "$ENV{HOME}/.ncustom"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 21 | eval {require NCustom::MyConfig;} ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 21 | shift @INC; | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 21 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # transaction | ||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | =item C<transaction> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | trasaction("tx1"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | Set the current trasaction. If not set it defaults to basename($0). Using the default is normally good enough. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 45 | ▶ | sub transaction{ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transaction: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 21 | my ($tx, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 21 | ▶ | $Transaction = ($tx || basename($0)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$tx || basename($0)
MC/DC0%0/2
$tx || basename($0)
$tx
basename($0)
Truth table33%1/3
A || B
A= $txB= basename($0)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # apply_config | ||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | =begin testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | &NCustom::apply_config(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | ▶ | ok( -d "$output/.ncustom/save/all") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | || diag("TEST:<NCustom> uses a save directory"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | ▶ | ok( -d "$output/.ncustom/tmp") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | || diag("TEST:<NCustom> uses a tmp directory"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | ▶ | -d "$output/.ncustom/save/all" || die; # as we could be way off course | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | =end testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 19 | ▶ | sub apply_config{ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_config: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | ▶ | if(! -d $Config{'save_dir'}){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | mkpath "$Config{'save_dir'}/all"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 19 | mkpath "$Config{'save_dir'}/all.new"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 18 | ▶ | -d $Config{'tmp_dir'} || mkpath $Config{'tmp_dir'}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | #TODO# error checking | ||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | #Q: whether should test src_fqdn (dns lookup/http get/ping) ? | ||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | #A: no, as might'nt ever matter that it is (potentially) incorrect/offline | ||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 18 | transaction(basename($0)); #so easy to override in testing | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 19 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # crud_gaurantee | ||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | =begin testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | my $msg; | |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | ▶ | ok( &NCustom::crud_gaurantee("$output/dir1/file1","read",\$msg) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | || diag("TEST:<crud_gaurantee> says if you can read a file."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | ok( &NCustom::crud_gaurantee("$output/dir1/file1","update",\$msg) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | || diag("TEST:<crud_gaurantee> says if you can update a file."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | ▶ | ok(!&NCustom::crud_gaurantee("$output/dir1/file9","update",\$msg) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | || diag("TEST:<crud_gaurantee> says if you cant update a file."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # should do more cant't testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # and test that get $msg | ||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | ▶ | ok( &NCustom::crud_gaurantee("$output/dir1/file1","delete",\$msg) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | || diag("TEST:<crud_gaurantee> says if you can delete a file."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | ▶ | ok( &NCustom::crud_gaurantee("$output/dir1/file9","create",\$msg) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | || diag("TEST:<crud_gaurantee> says if you can create a file."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | ▶ | ok( &NCustom::crud_gaurantee("$output/dir1/subdir1/file9","create",\$msg) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | || diag("TEST:<crud_gaurantee> says if you can create a file and its dirs."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | ▶ | ok( &NCustom::crud_gaurantee("$output/dir1/file1","r",\$msg) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | || diag("TEST:<crud_gaurantee> says if you can r a file (short notation)."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | ▶ | ok(!&NCustom::crud_gaurantee("$output/dir1/file9","r",\$msg) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | || diag("TEST:<crud_gaurantee> says if you cant r a file (short notation)."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | ok( &NCustom::crud_gaurantee("$output/dir1/file1","ru",\$msg) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | || diag("TEST:<crud_gaurantee> says if you can ru a file (short notation)."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # should do other crud combos | ||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | =end testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 122 | ▶ | sub crud_gaurantee{ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
crud_gaurantee: called CC=30 SCAR=39.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | my ($file, $check, $msgref) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | my $rc = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | #TODO# fix so dont fall through to success on invalid checks | ||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | #CRUD: Create guarantee | ||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # interpreting as create/clobber | ||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 122 | ▶ | if($check =~ /create/i || ($check =~ /^[crud]+$/i && $check =~ /c/i )){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$check =~ /create/i or $check =~ /^[crud]+$/i and $check =~ /c/i
$check =~ /^[crud]+$/i and $check =~ /c/i
MC/DC33%1/3
$check =~ /create/i or $check =~ /^[crud]+$/i and $check =~ /c/i
$check =~ /create/i
$check =~ /^[crud]+$/i
$check =~ /c/i
Truth table75%3/4
A or B and C
A= $check =~ /create/iB= $check =~ /^[crud]+$/iC= $check =~ /c/i
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 122 | ▶ | if(! -e dirname($file)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 122 | $rc = mkpath(dirname($file)); | |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 89 | ▶ | unless($rc){$$msgref = "Cant create dir for file: $file."; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if(! -w dirname($file)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $$msgref = "Cant create in dir for file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | if(-e $file && ! -f $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e $file and not -f $file
MC/DC0%0/2
-e $file and not -f $file
-e $file
not -f $file
Truth table66%2/3
A and not(B)
A= -e $fileB= not -f $file
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $$msgref = "Shant clobber existing non-plain-file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if(-f $file && ! -w $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-f $file and not -w $file
MC/DC100%2/2
-f $file and not -w $file
-f $file
not -w $file
Truth table100%3/3
A and not(B)
A= -f $fileB= not -w $file
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $$msgref = "Cant clobber existing plain-file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | #CRUD: Read guarantee | ||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 8 | ▶ | if($check =~ /read/i || ($check =~ /^[crud]+$/i && $check =~ /r/i )){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$check =~ /read/i or $check =~ /^[crud]+$/i and $check =~ /r/i
$check =~ /^[crud]+$/i and $check =~ /r/i
MC/DC66%2/3
$check =~ /read/i or $check =~ /^[crud]+$/i and $check =~ /r/i
$check =~ /read/i
$check =~ /^[crud]+$/i
$check =~ /r/i
Truth table75%3/4
A or B and C
A= $check =~ /read/iB= $check =~ /^[crud]+$/iC= $check =~ /r/i
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 8 | ▶ | if(! -e $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 114 | $$msgref = "Cant read non-existant file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | ▶ | if(! -f $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | $$msgref = "Shant read from non-plain-file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if(! -r $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $$msgref = "Cant read file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | #CRUD: Update guarantee | ||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if($check =~ /update/i || ($check =~ /^[crud]+$/i && $check =~ /u/i )){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$check =~ /update/i or $check =~ /^[crud]+$/i and $check =~ /u/i
$check =~ /^[crud]+$/i and $check =~ /u/i
MC/DC100%3/3
$check =~ /update/i or $check =~ /^[crud]+$/i and $check =~ /u/i
$check =~ /update/i
$check =~ /^[crud]+$/i
$check =~ /u/i
Truth table100%4/4
A or B and C
A= $check =~ /update/iB= $check =~ /^[crud]+$/iC= $check =~ /u/i
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if(! -e $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 113 | $$msgref = "Cant update non-existant file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | ▶ | if(! -f $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | $$msgref = "Shant update non-plain-file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if(! -r $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $$msgref = "Cant read file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if(! -w $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $$msgref = "Cant write file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | #CRUD: Delete guarantee | ||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 2 | ▶ | if($check =~ /delete/i || ($check =~ /^[crud]+$/i && $check =~ /d/i )){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$check =~ /delete/i or $check =~ /^[crud]+$/i and $check =~ /d/i
$check =~ /^[crud]+$/i and $check =~ /d/i
MC/DC33%1/3
$check =~ /delete/i or $check =~ /^[crud]+$/i and $check =~ /d/i
$check =~ /delete/i
$check =~ /^[crud]+$/i
$check =~ /d/i
Truth table75%3/4
A or B and C
A= $check =~ /delete/iB= $check =~ /^[crud]+$/iC= $check =~ /d/i
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | #TODO# implement when we need it | ||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 2 | ▶ | if(! -e $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 110 | $$msgref = "Cant delete non-existant file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | if(! -f $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $$msgref = "Shant delete non-plain-file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if(! -w dirname($file)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $$msgref = "Cant delete from dir of file: $file."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # save_files, save_file, save_file2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | =item C<save_files> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | ▶ | ok(-f "$output/dir2/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | || diag("TEST:<test setup> must copy over the subject dir"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | ▶ | can_ok("NCustom", qw(save_files)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | || diag("TEST:<save_files> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | save_files("~/dir2/file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | save_files(<<' EOF'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | ~/dir2/file2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | ~/dir3/* | ||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | There is not much point to this - the customise works or not. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | But it helps while developing the customisation. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | Note: changes effected by using NCustom functions are saved automatically. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | =for example_testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | ▶ | ok(-f "$output/.ncustom/save/all/$output/dir2/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | TEST:<save_files> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | TEST: - saves given file(s) to the overall archive | ||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | TEST: - performs filename expansion eg ~/ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | ok(-f "$output/.ncustom/save/tx1/$output/dir2/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | TEST:<save_files> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | TEST: - also saves given file(s) to the current tx archive | ||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | ▶ | ok(-f "$output/.ncustom/save/all/$output/dir2/file2") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | TEST:<save_files> multiple arguments: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | TEST: - accepts multiple arguments in one newline delimited string | ||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | TEST: - are also saved to both the overall, and current tx, archives 1/2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | ▶ | ok(-f "$output/.ncustom/save/tx1/$output/dir2/file2") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | TEST:<save_files> multiple arguments: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | TEST: - are also saved to both the overall, and current tx, archives 2/2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 1 | ▶ | ok(-f "$output/.ncustom/save/all/$output/dir3/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | || diag("TEST:<save_files> supports wildcarding 1/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 1 | ▶ | ok(-f "$output/.ncustom/save/tx1/$output/dir3/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | || diag("TEST:<save_files> supports wildcarding 2/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | ▶ | ok(-f "$output/.ncustom/save/all/$output/dir3/file2") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | || diag("TEST:<save_files> supports wildcarding 3/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | ▶ | ok(-f "$output/.ncustom/save/tx1/$output/dir3/file2") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | || diag("TEST:<save_files> supports wildcarding 4/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # extra tests | ||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | transaction("tx2"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | save_files("~/dir4/file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | ▶ | ok(-f "$output/.ncustom/save/tx2/$output/dir4/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | TEST:<save_files> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | TEST: - saves to a corresponding tx archive when the tx changes 1/2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | ▶ | ok(! -f "$output/.ncustom/save/tx1/$output/dir4/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | TEST:<save_files> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | TEST: - saves to a corresponding tx archive when the tx changes 2/2 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | copy("$input/dir4file1.v2", "$output/dir4/file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | save_files("~/dir4/file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | ▶ | my @matches = glob("$output/.ncustom/save/tx2/$output/dir4/*"); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | ▶ | is($#matches, 1) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | TEST:<save_files> if a file is saved to an archive, and it is already there: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | TEST: - the file will be saved with a suffix | ||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | #this better test didnt work because of filename mangling with samba | ||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | #ok(-f "$output/.ncustom/save/tx2/$output/dir4/file1.AT*") | ||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | save_files("~/dir4/file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 1 | @matches = glob("$output/.ncustom/save/tx2/$output/dir4/*"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 1 | ▶ | is($#matches, 1) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | TEST:<save_files> if a file is saved to an archive, and it is already there: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | TEST: - if there is no change it wont be saved again | ||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | sub save_file; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | ▶ | sub save_files { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_files: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my ($files, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 110 | my @lines = split(/\n/,$files); | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | my $status = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1 | my $line; | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 12 | foreach $line (@lines){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 12 | my ($file, @rest) = ($line =~ /\s*(.*)/); | |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 12 | ▶ | save_file($file) || ($status = 0); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 13 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | sub save_file2; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | sub expand_filenames; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 25 | ▶ | sub save_file { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_file: called CC=8 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | #save_file reduces the problem to dealing with indivudual files | ||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | #it then calls save_file2 to do the work | ||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 13 | my ($file, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 12 | my ($msg, $rc, $f, $global_dest, $local_dest); | |||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 25 | my $status = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 25 | foreach my $f ( expand_filenames($file)){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 25 | chomp $f; | |||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 25 | $global_dest = "$Config{'save_dir'}/all/$f"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 27 | $local_dest = "$Config{'save_dir'}/$Transaction/$f"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 27 | ▶ | save_file2($f, $global_dest) || ($status =0); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 27 | ▶ | save_file2($f, $local_dest) || ($status =0); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 27 | ▶ | if(! -e $f){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 1 | #So we must be dealing with a new file. | |||||||||||||||||||||||||||||||||||||||||||||||
| 511 | #For consistencey: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 27 | ▶ | -d "$Config{'save_dir'}/${Transaction}" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 1 | || mkpath "$Config{'save_dir'}/${Transaction}"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | #We have a special place for noting new files: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 27 | $global_dest = "$Config{'save_dir'}/all.new/$f"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 11 | $rc = crud_gaurantee($global_dest,"create",\$msg); | |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 11 | ▶ | unless($rc){carp "save_file: $msg"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | open(TOUCH,"> $global_dest"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | close(TOUCH); | |||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 11 | $local_dest = "$Config{'save_dir'}/${Transaction}.new/$f"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 11 | $rc = crud_gaurantee($local_dest,"create",\$msg); | |||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 11 | ▶ | unless($rc){carp "save_file: $msg"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | open(TOUCH,"> $local_dest"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | close(TOUCH); | |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 11 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 54 | ▶ | sub save_file2 { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_file2: called CC=8 SCAR=22.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 11 | my ($file, $dest, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 25 | my $rc = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 54 | my $msg; | |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 54 | my ($sec, $min, $hr) = (localtime)[0..2]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 54 | my $suffix = ".AT_$hr:$min:$sec" ;#also used in undo_file | |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | #TODO# $sec not fine grained enough, will get caught out one day | ||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 54 | ▶ | if(! -e $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | #we dont save something that doesnt exist | ||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | #but still relatively normal as we may be dealing with a new creation | ||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 54 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 54 | ▶ | if((-e $dest) && (compare($dest, $file) == 0)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e $dest and compare($dest, $file) == 0
MC/DC50%1/2
-e $dest and compare($dest, $file) == 0
-e $dest
compare($dest, $file) == 0
Truth table66%2/3
A and B
A= -e $destB= compare($dest, $file) == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | #already saved and files are the same | ||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | #TODO# add more checking here, -f, perms... | ||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | #carp "save_file: not saving, as not changed since last save: $file"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 22 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 32 | ▶ | if((-e $dest) && (compare($dest, $file) != 0)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $dest and compare($dest, $file) != 0
MC/DC0%0/2
-e $dest and compare($dest, $file) != 0
-e $dest
compare($dest, $file) != 0
Truth table33%1/3
A and B
A= -e $destB= compare($dest, $file) != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | #already saved but files are different | ||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | #better get a new name | ||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 4 | $dest = "${dest}$suffix"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 28 | $rc = crud_gaurantee($dest,"create",\$msg); | |||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | unless($rc){carp "save_file2: $msg"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | $rc = copy($file, $dest); | |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | unless($rc){carp "save_file2: copy failed: $file, $dest."; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 56 | ▶ | sub expand_filenames { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_filenames: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | my ($file_list, @rest) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 28 | my @result; | |||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | #tag# | ||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 56 | my @lines = split(/\n/,$file_list); | |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 56 | foreach my $line (@lines){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 56 | $line =~ s/^\s+//; #trim leading whitespace | |||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 56 | ▶ | next if $line =~ /^#/; #TODO# comments need much work | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | #TODO# find the perl fn for the following kludge | ||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | #cant use builtin glob as in some instances we're dealing with a newfile | ||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | #(builtin glob matches existing) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 58 | my @filename_expansion = split(/\s+/, `echo $line`); | |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 58 | foreach my $filename (@filename_expansion){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 58 | push @result, $filename; | |||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 58 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # initialise | ||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | =item C<initialise> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | ▶ | can_ok("NCustom", qw(initialise)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | || diag("TEST:<initialise> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 1 | initialise(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | Initialise the archive of saved files. As this deletes files this is not done automatically. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | =for example_testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 1 | @matches = glob("$output/.ncustom/save/*"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 1 | ▶ | is($#matches, 3) # ie 4 entries (all, all.new, tx1, tx1.new) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | || diag("TEST:<initialise> removes all save files"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 1 | ▶ | ok(-d "$output/.ncustom/save/all") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | || diag("TEST:<initialise> creates an empty skeleton save dir"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 1 | ▶ | sub initialise { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialise: called CC=8 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 1 | ▶ | rmtree($Config{'save_dir'}) || return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 1 | ▶ | mkpath("$Config{'save_dir'}/all") || return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 1 | ▶ | mkpath("$Config{'save_dir'}/all.new") || return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | ▶ | mkpath("$Config{'save_dir'}/$Transaction") || return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 1 | ▶ | mkpath("$Config{'save_dir'}/${Transaction}.new") || return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | ▶ | rmtree($Config{'tmp_dir'}) || return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 1 | ▶ | mkpath($Config{'tmp_dir'}) || return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | # commit_file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | =begin testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 1 | my $tmp = "$NCustom::Config{'tmp_dir'}"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 638 | #use tmp for files that will be altered/moved (to keep input unaltered) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 1 | copy("$input/dir5file1", "$tmp/dir5file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | &NCustom::commit_file("$tmp/dir5file1", "$output/dir5/file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 1 | ▶ | ok(-f "$output/dir5/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | || diag("TEST:<commit_file> checks in a new file"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 1 | ▶ | ok(! -f "$output/.ncustom/save/tx1/$output/dir5/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | || diag("TEST:<commit_file> doesnt archive files that didnt already exist"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | #TODO# that is interesting, that means that restore wont delete it | ||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | #TODO# could handle by save archiving filename.new, the resore knows to rm | ||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 1 | copy("$input/dir5file1.v2", "$tmp/dir5file1.v2"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 1 | &NCustom::commit_file("$tmp/dir5file1.v2", "$output/dir5/file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | ▶ | is(compare("$output/dir5/file1", "$input/dir5file1.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | || diag("TEST:<commit_file> checks in over an existing file"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | ▶ | is(compare("$output/.ncustom/save/tx1/$output/dir5/file1","$input/dir5file1"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | || diag("TEST:<commit_file> saves things before it clobbers them"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 1 | copy("$input/dir5file1", "$tmp/dir5file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 1 | &NCustom::commit_file("$tmp/dir5file1", "$output/dir5/subdir1/file1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 1 | ▶ | ok(-f "$output/dir5/subdir1/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | || diag("TEST:<commit_file> checks in a new file, creating subdirs required"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | =end testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 20 | ▶ | sub commit_file{ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commit_file: called CC=6 SCAR=19.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | my($newfile, $file, @rest) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 1 | my $rc = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 20 | my $msg; | |||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 1 | $rc = crud_gaurantee($newfile,"read delete",\$msg); | |||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1 | ▶ | unless($rc){carp "commit_file: $msg"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | $rc = crud_gaurantee($file,"create",\$msg); | |||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | unless($rc){carp "commit_file: $msg"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 8 | $rc = save_file($file); | |||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 8 | ▶ | unless($rc){ carp "commit_file: save_file: $file failed\n"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | $rc = copy($newfile, $file); | |||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | unless($rc){carp "commit_file: copy failed: $newfile, $file.\n"; return 0;} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | $rc = unlink($newfile); | |||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | ▶ | unless($rc){carp "commit_file: unlink failed: $newfile.\n"; return 0;} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # overwrite_file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | =item C<overwrite_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 1 | ▶ | can_ok("NCustom", qw(overwrite_file)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | || diag("TEST:<overwrite_file> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 1 | overwrite_file(file => "~/dir6/file1", text => ' some content'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 1 | overwrite_file(file => "~/dir6/file2", | |||||||||||||||||||||||||||||||||||||||||||||||
| 708 | strip => '^\s{4}', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | text => <<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | This will be line 1 of the new content of the file. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | This will be line 2 of the new content of the file. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | This, line3, will still be indented. As will line 4. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | I bet there will be a dollar sign and two single quotes on the next line. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 'I told you so ! Now you owe me $20', I would then say. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | This will be the last line. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | Overwrite file overwrites $file with $text. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | So that you can have pretty indentation when using here documents, the pattern $strip is stripped out prior to processing. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | More clearly, overwrite file is equivalent to: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | open(FILE,">$file"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | $text =~ s/$strip//; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | print FILE $text; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | =for example_testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 1 | ▶ | is(compare("$output/dir6/file1", "$input/dir6file1.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | TEST:<overwrite_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | TEST: - is logically equivalent to ">" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | TEST: - will not strip anything by default | ||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | TEST: - performs filename expansion eg ~/ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | TEST: - will create new file if required | ||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 1 | ▶ | is(compare("$output/dir6/file2", "$input/dir6file2.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | TEST:<overwrite_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | TEST: - will strip a given pattern from the text | ||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 1 | overwrite_file(file => "~/dir6/subdir1/file1", text => ' some content'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 1 | ▶ | is(compare("$output/dir6/subdir1/file1", "$input/dir6file1.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | TEST:<overwrite_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | TEST: - will create subdirs as needed for new files | ||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 15 | ▶ | sub change_file { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
change_file: called CC=10 SCAR=24.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my %args = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 1 | ▶ | my $change = ($args{'change'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'change'} || ''
MC/DC0%0/1
$args{'change'} || ''
$args{'change'}
Truth table50%1/2
A
A= $args{'change'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 15 | ▶ | my $files = ($args{'files'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'files'} || ''
MC/DC0%0/1
$args{'files'} || ''
$args{'files'}
Truth table50%1/2
A
A= $args{'files'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 1 | ▶ | my $body = ($args{'body'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'body'} || ''
MC/DC0%0/1
$args{'body'} || ''
$args{'body'}
Truth table50%1/2
A
A= $args{'body'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 1 | ▶ | my $strip = ($args{'strip'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'strip'} || ''
MC/DC100%1/1
$args{'strip'} || ''
$args{'strip'}
Truth table100%2/2
A
A= $args{'strip'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 1 | my $status = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 15 | my $rc = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | # input checks | ||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 15 | ▶ | if($files eq ""){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 15 | carp "change_file: file name is blank.\n"; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | ▶ | if($change !~ /^(overwrite|append|prepend|edit)$/){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | carp "change_file: Invalid type of change: $change."; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | # pre-process body (text / code) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | ▶ | $body =~ s/$strip//mg unless $strip eq ""; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | # pre-process filenames | ||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | # then invoke processing on each one | ||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | foreach my $file (expand_filenames($files)){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 15 | chomp $file; | |||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 15 | $rc = change_file2(change => $change, file => $file, body => $body); | |||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 17 | ▶ | unless($rc){$status = 0}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 17 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 17 | ▶ | sub change_file2 { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
change_file2: called CC=15 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 8 | my %args = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 15 | ▶ | my $change = ($args{'change'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'change'} || ''
MC/DC0%0/1
$args{'change'} || ''
$args{'change'}
Truth table50%1/2
A
A= $args{'change'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 17 | ▶ | my $file = ($args{'file'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'file'} || ''
MC/DC0%0/1
$args{'file'} || ''
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 17 | ▶ | my $body = ($args{'body'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'body'} || ''
MC/DC0%0/1
$args{'body'} || ''
$args{'body'}
Truth table50%1/2
A
A= $args{'body'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 17 | my $rc = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 17 | my $msg = ""; | |||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | #we use a tmp file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 17 | my $newfile = "$Config{'tmp_dir'}/" . basename($file); | |||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 1 | $rc = crud_gaurantee($newfile, "create", \$msg); | |||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 1 | ▶ | unless($rc){carp "change_file2: $msg"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | ▶ | if($change =~ /overwrite/ ){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | $rc = open(NEWFILE, ">$newfile"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 17 | print NEWFILE $body ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 6 | close(NEWFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 6 | ▶ | if($change =~ /append/ ){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 6 | ▶ | if( -e $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 17 | $rc = crud_gaurantee($file, "read", \$msg); | |||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 3 | ▶ | unless($rc){carp "change_file2: $msg"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | copy($file, $newfile); | |||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | open(NEWFILE, ">>$newfile"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 1 | print NEWFILE $body ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 3 | close(NEWFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 3 | ▶ | if($change =~ /prepend/ ){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 3 | open(NEWFILE, ">$newfile"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 17 | print NEWFILE $body ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 3 | close(NEWFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 3 | ▶ | -f $file && system("cat $file >> $newfile"); #TODO# do in perl | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 3 | ▶ | if($change =~ /edit/ ){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 3 | $rc = crud_gaurantee($file, "read", \$msg); | |||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 17 | ▶ | unless($rc){carp "change_file2: $msg"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | open(FILE, "<$file"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | open(NEWFILE, ">$newfile"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 826 | # select newfile, so prints in $body behave as expected | ||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 5 | my $old_fh = select(NEWFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 828 | # the action | ||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 2 | ▶ | no strict; no warnings ; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 5 | ▶ | while( <FILE> ){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 5 | eval $body; | |||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 5 | ▶ | if($@){carp "change_file2: code \n$body \nraised the error $@"; return 0;} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | } continue { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | print; | |||||||||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 2 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | close(NEWFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 17 | close(FILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 5 | select($old_fh); | |||||||||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 5 | return commit_file($newfile, $file); | |||||||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 6 | ▶ | sub overwrite_file { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
overwrite_file: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 5 | my %args = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 17 | ▶ | my $file = ($args{'file'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'file'} || ''
MC/DC0%0/1
$args{'file'} || ''
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 6 | ▶ | my $text = ($args{'text'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'text'} || ''
MC/DC0%0/1
$args{'text'} || ''
$args{'text'}
Truth table50%1/2
A
A= $args{'text'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 6 | ▶ | my $strip = ($args{'strip'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'strip'} || ''
MC/DC100%1/1
$args{'strip'} || ''
$args{'strip'}
Truth table100%2/2
A
A= $args{'strip'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 6 | return change_file(change => "overwrite", files => $file, | |||||||||||||||||||||||||||||||||||||||||||||||
| 853 | body => $text, strip => $strip); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # append_file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | =item C<append_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 1 | ▶ | can_ok("NCustom", qw(append_file)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | || diag("TEST:<append_file> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 1 | append_file(file => "~/dir7/file1", text => 'an extra line'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 1 | append_file(file => "~/dir7/file2", | |||||||||||||||||||||||||||||||||||||||||||||||
| 874 | strip => '^\s{4}', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | text => <<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | An extra line to add on to the file. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | This line, will be indented. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | The last last line with some special chars *!@$%.'" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | Append file is the same as overwrite file, except it behaves as ">>" instead of ">". | ||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | =for example_testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 1 | ▶ | is(compare("$output/dir7/file1", "$input/dir7file1.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | TEST:<append_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | TEST: - is logically equivalent to ">>" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | TEST: - will not strip anything by default | ||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | TEST: - performs filename expansion eg ~/ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | TEST: - will create new file if required | ||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 1 | ▶ | is(compare("$output/dir7/file2", "$input/dir7file2.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | TEST:<append_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | TEST: - will strip a given pattern from the text | ||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 1 | append_file(file => "~/dir7/subdir1/file1", text => 'an extra line'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 1 | ▶ | is(compare("$output/dir7/subdir1/file1", "$input/dir7file1.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | TEST:<append_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | TEST: - will create subdirs as needed for new files | ||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 3 | ▶ | sub append_file { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append_file: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 1 | my %args = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 1 | ▶ | my $file = ($args{'file'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'file'} || ''
MC/DC0%0/1
$args{'file'} || ''
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 3 | ▶ | my $text = ($args{'text'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'text'} || ''
MC/DC0%0/1
$args{'text'} || ''
$args{'text'}
Truth table50%1/2
A
A= $args{'text'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 1 | ▶ | my $strip = ($args{'strip'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'strip'} || ''
MC/DC100%1/1
$args{'strip'} || ''
$args{'strip'}
Truth table100%2/2
A
A= $args{'strip'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 1 | return change_file(change => "append", files => $file, | |||||||||||||||||||||||||||||||||||||||||||||||
| 917 | body => $text, strip => $strip); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | # prepend_file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | =item C<prepend_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 1 | ▶ | can_ok("NCustom", qw(prepend_file)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | || diag("TEST:<prepend_file> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 1 | prepend_file(file => "~/dir8/file1", text => 'an extra line'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 1 | prepend_file(file => "~/dir8/file2", | |||||||||||||||||||||||||||||||||||||||||||||||
| 938 | strip => '^\s{4}', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | text => <<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | An extra line at the start of the file. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | This line, will be indented. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | Some special chars *!@$%.'" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | The last extra line added to the start of the file. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | Prepend behaves the same as append, except the text is added to the start instead of the end. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 1 | =for example_testing | |||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 1 | ▶ | is(compare("$output/dir8/file1", "$input/dir8file1.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 1 | TEST:<prepend_file> | |||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 1 | TEST: - is logically equivalent to ">>" | |||||||||||||||||||||||||||||||||||||||||||||||
| 955 | TEST: - will not strip anything by default | ||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | TEST: - performs filename expansion eg ~/ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | TEST: - will create new file if required | ||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 1 | ▶ | is(compare("$output/dir8/file2", "$input/dir8file2.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | TEST:<prepend_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | TEST: - will strip a given pattern from the text | ||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 1 | prepend_file(file => "~/dir8/subdir1/file1", text => 'an extra line'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 1 | ▶ | is(compare("$output/dir8/subdir1/file1", "$input/dir8file1.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | TEST:<prepend_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | TEST: - will create subdirs as needed for new files | ||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 3 | ▶ | sub prepend_file { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepend_file: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 1 | my %args = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 1 | ▶ | my $file = ($args{'file'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'file'} || ''
MC/DC0%0/1
$args{'file'} || ''
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 3 | ▶ | my $text = ($args{'text'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'text'} || ''
MC/DC0%0/1
$args{'text'} || ''
$args{'text'}
Truth table50%1/2
A
A= $args{'text'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 1 | ▶ | my $strip = ($args{'strip'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'strip'} || ''
MC/DC100%1/1
$args{'strip'} || ''
$args{'strip'}
Truth table100%2/2
A
A= $args{'strip'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 1 | return change_file(change => "prepend", files => $file, | |||||||||||||||||||||||||||||||||||||||||||||||
| 982 | body => $text, strip => $strip); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | # edit_file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | =item C<edit_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 1 | ▶ | can_ok("NCustom", qw(edit_file)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | || diag("TEST:<edit_file> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 1 | edit_file(file => "~/dir9/file1", code => 's/file/FILE/g;'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 1 | edit_file(file => "~/dir9/file2", | |||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | strip => '^\s{4}', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | code => <<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | s/my\.example\.com/whatever\.com/g; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | s/^$/replace all blank lines with these three lines | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | two of three, with 4 leading spaces | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | and three of three/ ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | s/might/WILL/g; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 1 | edit_file(file => <<' EOF', strip => '^\s{6}', code => <<' EOF'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | ~/dir9/file3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | ~/dir10/* | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | s/file/FILE/g; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | s/least/LEASTWAYS/g; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | Edit file is similar to: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | perl -i -e "$code" $file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | With edit file, $file must exist. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | As with the other routines, $code has the pattern $strip stripped out. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | You can also provide multiple filenames to be editted. This holds true for the other routines too. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 1 | =for example_testing | |||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 1 | ▶ | is(compare("$output/dir9/file1", "$input/dir9file1.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 1 | TEST:<edit_file> | |||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 1 | TEST: - simple edit file | |||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 1 | ▶ | is(compare("$output/dir9/file2", "$input/dir9file2.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | TEST:<edit_file> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | TEST: - multi substitution edit | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 1 | ▶ | is(compare("$output/dir9/file3", "$input/dir9file3.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | || diag("TEST:<edit_file> - edits multiple files 1/3."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 1 | ▶ | is(compare("$output/dir10/file1", "$input/dir10file1.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | || diag("TEST:<edit_file> - edits multiple files 2/3."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 1 | ▶ | is(compare("$output/dir10/file2", "$input/dir10file2.v2"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | || diag("TEST:<edit_file> - edits multiple files 3/3."); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 3 | ▶ | sub edit_file { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edit_file: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 1 | my %args = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 1 | ▶ | my $file = ($args{'file'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'file'} || ''
MC/DC0%0/1
$args{'file'} || ''
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 3 | ▶ | my $code = ($args{'code'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'code'} || ''
MC/DC0%0/1
$args{'code'} || ''
$args{'code'}
Truth table50%1/2
A
A= $args{'code'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 1 | ▶ | my $strip = ($args{'strip'} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'strip'} || ''
MC/DC100%1/1
$args{'strip'} || ''
$args{'strip'}
Truth table100%2/2
A
A= $args{'strip'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 1 | return change_file(change => "edit", files => $file, | |||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | body => $code, strip => $strip); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | # undo_files | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | =item C<undo_files> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 1 | ▶ | can_ok("NCustom", qw(undo_files)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | || diag("TEST:<undo_files> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 1 | save_files("~/dir11/file1 ~/dir11/file2"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 1 | transaction("tx2"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 1 | save_files("~/dir11/file3"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 1 | transaction("tx3"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 1 | save_files("~/dir11/file4"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 1 | transaction("tx4"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 1 | save_files("~/dir11/file5"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 1 | transaction("tx5"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 1 | save_files("~/dir11/file6"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 1 | transaction("tx6"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 1 | save_files("~/dir11/file7"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 1 | transaction("tx7"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 1 | save_files("~/dir11/file8"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 1 | rmtree("$output/dir11"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 1 | mkpath("$output/dir11"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 1 | undo_files("tx1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 1 | undo_files("~/.ncustom/save/tx2"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 1 | undo_files("tx3 tx4"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 1 | undo_files(<<' EOF'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | tx5 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | ~/.ncustom/save/tx6 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | Undo transaction will restore the files from a given transaction archive directory. That includes removing any new files that were created. For any directories that it cannot find, it will try looking in $Config{'save_dir'}. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | Undo does not: restore files that were edited by non-NCustom function if they were not first saved using NCuston::save_files; delete new directories that were created (yet). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | Again: this is only a development aid. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 1 | =for example_testing | |||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 1 | ▶ | ok(-f "$output/dir11/file1" && -f "$output/dir11/file2") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f "$output/dir11/file1" && -f "$output/dir11/file2"
MC/DC0%0/2
-f "$output/dir11/file1" && -f "$output/dir11/file2"
-f "$output/dir11/file1"
-f "$output/dir11/file2"
Truth table33%1/3
A && B
A= -f "$output/dir11/file1"B= -f "$output/dir11/file2"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | || diag("TEST:<undo_files> restores files for a given customisation"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 1 | ▶ | ok(-f "$output/dir11/file3") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 1 | || diag("TEST:<undo_files> restores files for a given directory"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 1 | ▶ | ok(-f "$output/dir11/file4" && -f "$output/dir11/file5") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f "$output/dir11/file4" && -f "$output/dir11/file5"
MC/DC0%0/2
-f "$output/dir11/file4" && -f "$output/dir11/file5"
-f "$output/dir11/file4"
-f "$output/dir11/file5"
Truth table33%1/3
A && B
A= -f "$output/dir11/file4"B= -f "$output/dir11/file5"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | || diag("TEST:<undo_files> restores for multiple customisations at once"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 1 | ▶ | ok(-f "$output/dir11/file6" && -f "$output/dir11/file7") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f "$output/dir11/file6" && -f "$output/dir11/file7"
MC/DC0%0/2
-f "$output/dir11/file6" && -f "$output/dir11/file7"
-f "$output/dir11/file6"
-f "$output/dir11/file7"
Truth table33%1/3
A && B
A= -f "$output/dir11/file6"B= -f "$output/dir11/file7"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | || diag("TEST:<undo_files> handles mixed multi-line arguments"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 1 | ▶ | ok(!-f "$output/dir11/file8") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | || diag("TEST:<undo_files> doesnt restore too much"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 1 | undo_files("all"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 1 | ▶ | ok(-f "$output/dir11/file8") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | || diag("TEST:<undo_files> will restore all"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 1 | transaction("tx8"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 1 | mkpath("$output/dir12/subdir1"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 1 | overwrite_file(file => "~/dir12/file1", text => ' some content'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 1 | transaction("tx9"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 1 | overwrite_file(file => "~/dir12/file2", text => ' some content'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 1 | transaction("tx10"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 1 | overwrite_file(file => "~/dir12/file3", text => ' some content'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 1 | ▶ | ok( -f "$output/dir12/file1" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
-f "$output/dir12/file1" && -f "$output/dir12/file2" && -f "$output/dir12/file3"
-f "$output/dir12/file1" and -f "$output/dir12/file2"
MC/DC0%0/3
-f "$output/dir12/file1" && -f "$output/dir12/file2" && -f "$output/dir12/file3"
-f "$output/dir12/file1"
-f "$output/dir12/file2"
-f "$output/dir12/file3"
Truth table25%1/4
A and B && C
A= -f "$output/dir12/file1"B= -f "$output/dir12/file2"C= -f "$output/dir12/file3"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | && -f "$output/dir12/file2" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | && -f "$output/dir12/file3") | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | || diag("TEST:<test setup> new files are setup ready for undo test"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 1 | undo_files("tx8"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 1 | ▶ | ok(! -f "$output/dir12/file1") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | || diag("TEST:<undo_files> removes newly created files"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 1 | ▶ | ok(-f "$output/dir12/file2" && -f "$output/dir12/file3") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f "$output/dir12/file2" && -f "$output/dir12/file3"
MC/DC0%0/2
-f "$output/dir12/file2" && -f "$output/dir12/file3"
-f "$output/dir12/file2"
-f "$output/dir12/file3"
Truth table33%1/3
A && B
A= -f "$output/dir12/file2"B= -f "$output/dir12/file3"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | || diag("TEST:<undo_files> doesnt removes too much"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 1 | undo_files("all"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 1 | ▶ | ok( ! -f "$output/dir12/file1" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
-f "$output/dir12/file1" || -f "$output/dir12/file2" || -f "$output/dir12/file3"
-f "$output/dir12/file1" or -f "$output/dir12/file2"
MC/DC0%0/3
-f "$output/dir12/file1" || -f "$output/dir12/file2" || -f "$output/dir12/file3"
-f "$output/dir12/file1"
-f "$output/dir12/file2"
-f "$output/dir12/file3"
Truth table25%1/4
A or B || C
A= -f "$output/dir12/file1"B= -f "$output/dir12/file2"C= -f "$output/dir12/file3"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | && ! -f "$output/dir12/file2" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | && ! -f "$output/dir12/file3") | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | || diag("TEST:<undo_files> removes all new files for \"all\" transaction"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | sub undo_file ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 1 | sub delete_file ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 1 | ▶ | sub undo_files{ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
undo_files: called CC=9 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 3 | my ($names, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 1 | my $status = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 1 | #tag# | |||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 7 | foreach my $dir ( expand_filenames($names)){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | 7 | ▶ | if(! -e $dir){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | # if dir (ie tx) to undo isnt an absolute dir, assume relative to save_dir | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 7 | $dir = "$Config{'save_dir'}/$dir"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | # now we need to expand again, as it may be wildcarded | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 9 | foreach my $d ( expand_filenames($dir)){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 7 | ▶ | if(! -e $d){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 9 | carp "undo_files: dir doesnt exist: $d."; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 9 | $status = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | #TODO# maybe dont need this restriction, makes it safer though... | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | #restrict to existing archive dirs (transactions) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 0 | ▶ | if( $d !~ m|$Config{'save_dir'}/([^/]*)| ){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 0 | carp "undo_files: dir isnt an archive dir: $d."; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 9 | $status = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | #print "\nRestoring files from archive dir: $d \n\t"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 0 | ▶ | find(\&undo_file, "$d") || ($status = 0); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | #print "\nDeleting files that didnt exist before: $d \n\t"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | #dir undoing may be a subtree of a transaction's archive dir | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | #so get the corresponding subtree of archive.new dir | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 0 | my $d_new = $d ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 9 | $d_new =~ s|($Config{'save_dir'}/[^/]*)|$1.new| ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 9 | ▶ | if( -e $d_new){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | 9 | ▶ | find(\&delete_file, $d_new) || ($status = 0); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 9 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 96 | ▶ | sub undo_file { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
undo_file: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 3 | my $file = $File::Find::name ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 7 | my ($dest, @rest) = ($file =~ m|$Config{'save_dir'}/[^/]*(.*)| ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 96 | ▶ | if($file =~ /\.AT_\d+:\d+:\d+$/ ){ #suffix set in save_file2 | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 96 | return 1; # not restoring non-original saves | |||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | ▶ | if(! -f $file ){return 1} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 96 | copy($file, $dest); #TODO# too silent on errors, however justified | |||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 73 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 23 | ▶ | sub delete_file { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_file: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 1 | my $archive_filename = $File::Find::name ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 23 | my ($real_filename, @rest) = | |||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | ($archive_filename =~ m|$Config{'save_dir'}/[^/]*(.*)| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | 1 | ▶ | if(! -f $archive_filename ){return 1} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 23 | my $rc = unlink($real_filename); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | #silent, as may fail unlink as may already have been deleted | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | #when undid a transaction, so cant unlink again when do undo all | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | #unless($rc){carp "delete_file: unlink: $!";} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 19 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | # check_pkg | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | =begin testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 1 | system('rpm -e perl-NCustomDummy > /dev/null 2>&1'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 1 | my $junk = "JUNK gg"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 1 | ▶ | ok(! &NCustom::check_pkg($junk)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | || diag("TEST:<check_pkg> checks input format"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | # supress expected error message: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 1 | $_STDERR_ =~ s/check_pkg: invalid arguments. at lib\/NCustom.pm line \d+\n// ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | 1 | my $req = { match => "", version => "0.0.0", pkg => "", result => ""}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | 1 | my $p = "perl-NCustomDummy"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | 1 | $req = { match => "MINIMUM", version => "0.0.0", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "MISSING") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | || diag("TEST:<check_pkg> checks if package meets minimum version 1/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | 1 | $req = { match => "MAXIMUM", version => "0.0.0", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "MISSING") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | || diag("TEST:<check_pkg> checks if package meets maximum version 1/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | 1 | $req = { match => "EXACTLY", version => "0.0.0", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "MISSING") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | || diag("TEST:<check_pkg> checks if package meets exact version 1/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | 1 | $req = { match => "NOTWANT", version => "0.0.0", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "OK") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | || diag("TEST:<check_pkg> checks if package present 1/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | 1 | system("rpm -i $input/perl-NCustomDummy-1.23-1.noarch.rpm"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | #shouldnt assume this works | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 1 | $req = { match => "MINIMUM", version => "1.09.1", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "OK") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | || diag("TEST:<check_pkg> checks if package meets minimum version 2/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 1 | $req = { match => "MINIMUM", version => "1.23", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "OK") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | || diag("TEST:<check_pkg> checks if package meets minimum version 3/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | 1 | $req = { match => "MINIMUM", version => "1.99.9", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "BELOW") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | || diag("TEST:<check_pkg> checks if package meets minimum version 4/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 1 | $req = { match => "MAXIMUM", version => "1.09.1", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "ABOVE") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | || diag("TEST:<check_pkg> checks if package meets maximum version 2/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 1 | $req = { match => "MAXIMUM", version => "1.23", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "OK") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | || diag("TEST:<check_pkg> checks if package meets maximum version 3/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 1 | $req = { match => "MAXIMUM", version => "1.99.9", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "OK") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | || diag("TEST:<check_pkg> checks if package meets maximum version 4/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 1 | $req = { match => "EXACTLY", version => "1.09.1", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "ABOVE") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | || diag("TEST:<check_pkg> checks if package meets exact version 2/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 1 | $req = { match => "EXACTLY", version => "1.23", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "OK") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | || diag("TEST:<check_pkg> checks if package meets exact version 3/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 1 | $req = { match => "EXACTLY", version => "1.99.9", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "BELOW") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | || diag("TEST:<check_pkg> checks if package meets exact version 4/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | 1 | $req = { match => "NOTWANT", version => "1.09.1", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "UNWELCOME") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | || diag("TEST:<check_pkg> checks if package present 2/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 1 | $req = { match => "NOTWANT", version => "1.23", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "UNWELCOME") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | || diag("TEST:<check_pkg> checks if package present 3/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 1 | $req = { match => "NOTWANT", version => "1.99.9", pkg => $p, result=>"" }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 1 | ▶ | &NCustom::check_pkg($req); is($$req{'result'}, "UNWELCOME") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | || diag("TEST:<check_pkg> checks if package present 4/4"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | =end testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | sub vcmp ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 1 | ▶ | sub check_pkg { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_pkg: called CC=15 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 1 | my ($req, @rest) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | #$req = { match => "", version => "", pkg => "", result => ""}; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | 4 | ▶ | if(! defined $$req{'match'}){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 21 | carp "check_pkg: invalid arguments."; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 21 | return 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 1 | ▶ | if($$req{'match'} !~ /(MINIMUM)|(MAXIMUM)|(EXACTLY)|(NOTWANT)/){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 1 | carp "check_pkg: invalid argument values."; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 20 | return 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 0 | my $rc = system("rpm -q $$req{'pkg'}"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 0 | ▶ | if(($rc == 0)and($$req{'match'} =~ /NOTWANT/)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rc == 0 and $req->{"match"} =~ /NOTWANT/
MC/DC0%0/2
$rc == 0 and $req->{"match"} =~ /NOTWANT/
$rc == 0
$req->{"match"} =~ /NOTWANT/
Truth table33%1/3
A and B
A= $rc == 0B= $req->{"match"} =~ /NOTWANT/
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 20 | $$req{'result'} = "UNWELCOME"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 20 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 0 | ▶ | if(($rc != 0)and($$req{'match'} =~ /NOTWANT/)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rc != 0 and $req->{"match"} =~ /NOTWANT/
MC/DC50%1/2
$rc != 0 and $req->{"match"} =~ /NOTWANT/
$rc != 0
$req->{"match"} =~ /NOTWANT/
Truth table66%2/3
A and B
A= $rc != 0B= $req->{"match"} =~ /NOTWANT/
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | 0 | $$req{'result'} = "OK"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | 20 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | 6 | ▶ | if(($rc != 0)and($$req{'match'} !~ /NOTWANT/)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rc != 0 and not $req->{"match"} =~ /NOTWANT/
MC/DC0%0/2
$rc != 0 and not $req->{"match"} =~ /NOTWANT/
$rc != 0
not $req->{"match"} =~ /NOTWANT/
Truth table33%1/3
A and not(B)
A= $rc != 0B= not $req->{"match"} =~ /NOTWANT/
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 6 | $$req{'result'} = "MISSING"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 14 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 14 | my $ver = `rpm -q $$req{'pkg'} --qf \%{VERSION}` . ""; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | 14 | my $reqver = "$$req{'version'}" . ""; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | # vstring will be deprecated, by then we'll find a module for it | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 0 | ▶ | if(($$req{'match'} =~ /EXACTLY/) and(vcmp($ver, "eq", $reqver))){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$req->{"match"} =~ /EXACTLY/ and vcmp($ver, "eq", $reqver)
MC/DC0%0/2
$req->{"match"} =~ /EXACTLY/ and vcmp($ver, "eq", $reqver)
$req->{"match"} =~ /EXACTLY/
vcmp($ver, "eq", $reqver)
Truth table0%0/3
A and B
A= $req->{"match"} =~ /EXACTLY/B= vcmp($ver, "eq", $reqver)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 0 | $$req{'result'} = "OK"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 0 | ▶ | if(($$req{'match'} =~ /MINIMUM|EXACTLY/) and(vcmp($ver, "lt", $reqver))){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$req->{"match"} =~ /MINIMUM|EXACTLY/ and vcmp($ver, "lt", $reqver)
MC/DC0%0/2
$req->{"match"} =~ /MINIMUM|EXACTLY/ and vcmp($ver, "lt", $reqver)
$req->{"match"} =~ /MINIMUM|EXACTLY/
vcmp($ver, "lt", $reqver)
Truth table0%0/3
A and B
A= $req->{"match"} =~ /MINIMUM|EXACTLY/B= vcmp($ver, "lt", $reqver)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 0 | $$req{'result'} = "BELOW"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 0 | ▶ | if(($$req{'match'} =~ /MAXIMUM|EXACTLY/) and(vcmp($ver, "gt", $reqver))){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$req->{"match"} =~ /MAXIMUM|EXACTLY/ and vcmp($ver, "gt", $reqver)
MC/DC0%0/2
$req->{"match"} =~ /MAXIMUM|EXACTLY/ and vcmp($ver, "gt", $reqver)
$req->{"match"} =~ /MAXIMUM|EXACTLY/
vcmp($ver, "gt", $reqver)
Truth table0%0/3
A and B
A= $req->{"match"} =~ /MAXIMUM|EXACTLY/B= vcmp($ver, "gt", $reqver)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 0 | $$req{'result'} = "ABOVE"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | # fall-through is brave ? check this logic | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | 0 | $$req{'result'} = "OK"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | # required_packages | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | =item C<required_packages> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | 1 | ▶ | can_ok("NCustom", qw(required_packages)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | || diag("TEST:<required_packages> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | #that was test 93 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 0 | ▶ | sub handler{ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handler: not called CC=1 SCAR=2.6
Subroutine
handler: called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 0 | my ($reqref, $url, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 0 | print "As $$reqref{'match'} version $$reqref{'version'} of "; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | 0 | print "$$reqref{'pkg'} was $$reqref{'result'} - "; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | 0 | print "we are going to fetch $file from $url and execute it.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 0 | print "This should set things right.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | 1 | required_packages(<<' EOF'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | EXACTLY; 9.9.9; acme; handler($req, "URL", "FILE") | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | NOTWANT; 0.0.0; perl; print "Dont be stupid\n" | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | #MAXIMUM; 9.9.9; perl; carp("Warning: untested with this perl") | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | #MINIMUM; 9.9.9; perl; apt_fix() | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | NOTWANT; 0.0.0; perl; for($i = 0; $i < 10; $i++){$s="Hello"; print "${s}${i}\n"} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | Required packages take a multi-line argument list, where each line is of the format: requirement, version, package, handler code. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | Required packages will invoke the handler if the package is (or isnt) installed as per the requirement and version. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | Valid requirements are: MINUMUM, MAXUMUM, EXACTLY, and NOTWANT. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | Input lines will be ignored if the first non-whitespace character is the '#' character. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | The handler code is eval'd, and it may make use of the hashref "req". The hash has the keys: match, version, and package; which correspond to the original arguments. The hash also contains result, which is the answer as to whether the requirements was met or not. Possible values of result (each referring to the package or it's version in relation to the requuirements) are: MISSING, ABOVE, BELOW, or UNWELCOME. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | A handler "apt_fix" is provided that will simply attempt to remove UNWELCOME packages, and do an install for all other scenarios - so you might get the verion you want or not, depending upon your apt repository. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | =for example_testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | 1 | my $o = $_STDOUT_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | 1 | my $e = $_STDERR_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | 1 | ▶ | like($o, qr/As EXACTLY version .* fetch FILE from URL and execute it.\n/) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | || diag("TEST:<required_packages> calls a handler"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | 1 | ▶ | like($o, qr/Dont be stupid/) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | || diag("TEST:<required_packages> executes simple statements"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | 1 | ▶ | like($o, qr/Hello9/) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | || diag("TEST:<required_packages> executes compound statements"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | # supress expected output | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | 1 | $_STDOUT_ =~ s/Hello\d+\n//gm ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 1 | $_STDOUT_ =~ s/Dont be stupid\n//gm ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | 1 | $_STDOUT_ =~ s/As EXACTLY version .* fetch FILE from URL and execute it.\n//gm ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | 1 | $_STDOUT_ =~ s/This should set things right.\n//gm ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | 1 | ▶ | sub required_packages { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
required_packages: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | 1 | my ($requirements, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | 1 | my $status = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 1 | my $rc = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | 1 | my @lines = split(/\n/,$requirements); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 1 | foreach my $line (@lines){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | 1 | $line =~ s/^\s+//; #trim leading whitespace | |||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | 1 | ▶ | next if $line =~ /^#/; #TODO# comments need much work | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | 5 | $req = { match => "", version => "0.0.0", pkg => "", result => ""}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | 5 | ($$req{'match'}, $$req{'version'}, $$req{'pkg'}, my @rest) | |||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | = parse_line('\s*;\s*',1, $line); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 3 | my $code = join(';',@rest); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | 3 | $rc = check_pkg($req); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | 3 | ▶ | unless($rc){$status = 0; next} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | 0 | ▶ | if($$req{'result'} ne "OK"){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | #we invoke handler from caller's perspective | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | package main ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 2 | ▶ | no strict; no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | 0 | eval $code ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 3 | ▶ | if($@){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | 1 | carp("required_packages: code \n$code \nraised the error $@"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | 1 | $NCustom::status = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 2 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | #back to normal | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | package NCustom ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | 0 | $rc = check_pkg($req); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 0 | ▶ | unless(($$req{'result'} eq "OK") && ($rc)){ $status = 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$NCustom::req->{"result"} eq "OK" and $rc
MC/DC0%0/2
$NCustom::req->{"result"} eq "OK" and $rc
$NCustom::req->{"result"} eq "OK"
$rc
Truth table33%1/3
A and B
A= $NCustom::req->{"result"} eq "OK"B= $rc
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | 1 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | # apt_fix | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | =begin testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | SKIP: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 1 | ▶ | skip "apt too intrusive", 6 unless (defined $ENV{'TEST_APT'} || defined $ENV{'TEST_ALL'}); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ENV{"TEST_APT"} or defined $ENV{"TEST_ALL"}
MC/DC0%0/2
defined $ENV{"TEST_APT"} or defined $ENV{"TEST_ALL"}
defined $ENV{"TEST_APT"}
defined $ENV{"TEST_ALL"}
Truth table33%1/3
A or B
A= defined $ENV{"TEST_APT"}B= defined $ENV{"TEST_ALL"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | ############# | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | 1 | system('rpm -e perl-NCustomDummy > /dev/null 2>&1'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | 1 | my ($version, $rc); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | 0 | $version = `rpm -q perl-NCustomDummy --qf \%{VERSION}`; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | 0 | ▶ | like($version, qr/package perl-NCustomDummy is not installed/) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | || diag("TEST:<test setup> must remove perl-NCustomDummy package"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | 0 | ▶ | can_ok("NCustom", qw(apt_fix)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | || diag("TEST:<apt_fix> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | 0 | $rc = required_packages(<<' EOF'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | EXACTLY; 9.9.9; perl-NCustomDummy; apt_fix() | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 0 | ▶ | ok(! $rc) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | || diag("TEST:<required_packages> must return 0 if requirements arent met"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 0 | $version = `rpm -q perl-NCustomDummy --qf \%{VERSION}`; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | 0 | ▶ | like($version, qr/1.23/) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | || diag("TEST:<apt_fix> must will install its version rather than nothing"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | 0 | $rc = required_packages(<<' EOF'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | NOTWANT; 9.9.9; perl-NCustomDummy; apt_fix() | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | 0 | ▶ | is($rc, 1) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | || diag("TEST:<required_packages> must return 1 if requirements are met"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | 0 | $version = `rpm -q perl-NCustomDummy --qf \%{VERSION}`; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | 0 | ▶ | like($version, qr/package perl-NCustomDummy is not installed/) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | || diag("TEST:<apt_fix> will remove unwanted packages"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | ############ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | 0 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | =end testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | 0 | ▶ | sub apt_fix { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apt_fix: not called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | 1 | ▶ | if($$req{'result'} =~ /UNWELCOME/){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | 1 | system("apt-get -q -y remove $$req{'pkg'}"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | 0 | system("apt-get -q -y install $$req{'pkg'}"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | 0 | return 1; #hmm | |||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | # vcmp | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | =begin testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | #FALSE | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | 1 | ▶ | ok(! &NCustom::vcmp(1,"gt",2) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | 1 | ▶ | ok(! &NCustom::vcmp(1,"eq",2) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | 1 | ▶ | ok(! &NCustom::vcmp(3,"gt",3) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | 1 | ▶ | ok(! &NCustom::vcmp(3,"lt",3) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | 1 | ▶ | ok(! &NCustom::vcmp(3,"ne",3) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | #TRUE"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | 1 | ▶ | ok(&NCustom::vcmp(1,"lt",2) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | 1 | ▶ | ok(&NCustom::vcmp(1,"ne",2) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | 1 | ▶ | ok(&NCustom::vcmp(3,"eq",3) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | 1 | ▶ | ok(&NCustom::vcmp("1.2.3","lt",2) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | 1 | ▶ | ok(&NCustom::vcmp("1.2.3","gt","1.1.99") ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | 1 | ▶ | ok(&NCustom::vcmp("1.2.3","eq","1.2.3") ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | 1 | ▶ | ok(&NCustom::vcmp(1,"ne",0) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | 1 | ▶ | ok(&NCustom::vcmp("1.2.3","lt",2) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | 1 | ▶ | ok(&NCustom::vcmp("1.2.3","gt","1.1.99") ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | 1 | ▶ | ok(&NCustom::vcmp("1.2.3","eq","1.2.3") ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | 1 | ▶ | ok(&NCustom::vcmp(1,"ne",0) ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | 1 | ▶ | ok(&NCustom::vcmp("1.2.3","lt","1.03") ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | || diag("TEST:<vcmp> compares version strings"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | =end testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | 1 | #==================================================================== | |||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | 1 | ▶ | sub vcmp { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vcmp: called CC=41 SCAR=48.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | 0 | my ($vstring1, $cmp, $vstring2) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | 0 | my ($v1, $v2, $dummy, @rest); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | # check input ###################################### | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | 30 | ▶ | if( $cmp !~ /(lt)|(gt)|(eq)|(ne)/ ){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | 30 | carp "vcmp: invalid comparision operator: $cmp.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | 30 | return 0; #arbitrary | |||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | 0 | ▶ | if( $vstring1 !~ /^(\d+\.)*\d*$/ ){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | 0 | carp "vcmp: invalid version string: $vstring1.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | 30 | return 0; #arbitrary | |||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | 0 | ▶ | if( $vstring2 !~ /^(\d+\.)*\d*$/ ){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | 0 | carp "vcmp: invalid version string: $vstring2.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | 30 | return 0; #arbitrary | |||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | # reduce ########################################### | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | 0 | $vstring1 =~ s/^\.*([^\.]+)\.*// ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | 0 | $v1 = $1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | #if($v1 eq ""){$v1 = 0} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | #if($vstring1 eq ""){$vstring1 = 0} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | #print "\n\t\tv1: $v1 vstring1: $vstring1 "; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | 30 | $vstring2 =~ s/^\.*([^\.]+)\.*// ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | 30 | $v2 = $1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | #if($v2 eq ""){$v2 = 0} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | #if($vstring2 eq ""){$vstring2 = 0} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | #print "\n\t\tv2: $v2 vstring2: $vstring2 "; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | # result/recuse ################################### | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | 30 | ▶ | if( $cmp eq "eq"){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | 30 | ▶ | if((! defined $v1) and (! defined $v2)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
defined $v1 || defined $v2
MC/DC50%1/2
defined $v1 || defined $v2
defined $v1
defined $v2
Truth table66%2/3
A || B
A= defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | ▶ | }elsif((! defined $v1) or (! defined $v2)){ | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $v1 && defined $v2
MC/DC0%0/2
defined $v1 && defined $v2
defined $v1
defined $v2
Truth table33%1/3
A && B
A= defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | 11 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | 1 | }elsif( $v1 != $v2 ){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | }elsif( $v1 != $v2 ){ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | 0 | return vcmp($vstring1, $cmp, $vstring2) ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | 1 | ▶ | if( $cmp eq "ne"){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | 7 | ▶ | if((! defined $v1) and (! defined $v2)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
defined $v1 || defined $v2
MC/DC50%1/2
defined $v1 || defined $v2
defined $v1
defined $v2
Truth table66%2/3
A || B
A= defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | 19 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | ▶ | }elsif((! defined $v1) or (! defined $v2)){ | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $v1 && defined $v2
MC/DC0%0/2
defined $v1 && defined $v2
defined $v1
defined $v2
Truth table33%1/3
A && B
A= defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | }elsif( $v1 != $v2 ){ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | ▶ | }elsif($v1 eq "" && $v2 eq ""){ | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$v1 eq "" and $v2 eq ""
MC/DC0%0/2
$v1 eq "" and $v2 eq ""
$v1 eq ""
$v2 eq ""
Truth table33%1/3
A and B
A= $v1 eq ""B= $v2 eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | 3 | return vcmp($vstring1, $cmp, $vstring2) ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | 0 | ▶ | if( $cmp eq "lt"){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | 1 | ▶ | if((! defined $v1) and (! defined $v2)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition66%2/3
defined $v1 || defined $v2
MC/DC50%1/2
defined $v1 || defined $v2
defined $v1
defined $v2
Truth table66%2/3
A || B
A= defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | 14 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | ▶ | }elsif((! defined $v1) and ( defined $v2)){ | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not defined $v1 and defined $v2
MC/DC0%0/2
not defined $v1 and defined $v2
not defined $v1
defined $v2
Truth table33%1/3
not(A) and B
A= not defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | 7 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | ▶ | }elsif(( defined $v1) and (!defined $v2)){ | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $v1 and not defined $v2
MC/DC0%0/2
defined $v1 and not defined $v2
defined $v1
not defined $v2
Truth table33%1/3
A and not(B)
A= defined $v1B= not defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | }elsif( $v1 < $v2 ){ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | }elsif($v1 > $v2 ){ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | ▶ | }elsif($v1 eq "" && $v2 eq ""){ | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$v1 eq "" and $v2 eq ""
MC/DC0%0/2
$v1 eq "" and $v2 eq ""
$v1 eq ""
$v2 eq ""
Truth table33%1/3
A and B
A= $v1 eq ""B= $v2 eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | 0 | return vcmp($vstring1, $cmp, $vstring2) ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | 0 | ▶ | if( $cmp eq "gt"){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | 2 | ▶ | if((! defined $v1) and (! defined $v2)){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition66%2/3
defined $v1 || defined $v2
MC/DC50%1/2
defined $v1 || defined $v2
defined $v1
defined $v2
Truth table66%2/3
A || B
A= defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | 7 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | ▶ | }elsif((! defined $v1) and ( defined $v2)){ | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not defined $v1 and defined $v2
MC/DC0%0/2
not defined $v1 and defined $v2
not defined $v1
defined $v2
Truth table33%1/3
not(A) and B
A= not defined $v1B= defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | 7 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | ▶ | }elsif(( defined $v1) and (!defined $v2)){ | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $v1 and not defined $v2
MC/DC0%0/2
defined $v1 and not defined $v2
defined $v1
not defined $v2
Truth table33%1/3
A and not(B)
A= defined $v1B= not defined $v2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | }elsif( $v1 > $v2 ){ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | }elsif($v1 < $v2 ){ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | ▶ | }elsif($v1 eq "" && $v2 eq ""){ | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$v1 eq "" and $v2 eq ""
MC/DC0%0/2
$v1 eq "" and $v2 eq ""
$v1 eq ""
$v2 eq ""
Truth table33%1/3
A and B
A= $v1 eq ""B= $v2 eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | #}elsif($v1 == 0 && $v2 == 0){ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | 1 | return vcmp($vstring1, $cmp, $vstring2) ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | # blat_myconfig | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | =item C<blat_myconfig> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | 1 | ▶ | can_ok("NCustom", qw(blat_myconfig)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | || diag("TEST:<blat_myconfig> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | 1 | blat_myconfig(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1677 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1678 | Blat_myconfig overwrites the personal configuration profile with the global configuration profile. The personal configuration profile is "~/.ncustom/NCustom/MyConfig.pm". | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1679 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1680 | =for example_testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1681 | 1 | ▶ | is(compare("$output/.ncustom/NCustom/MyConfig.pm", "$input/Global.pm"), 0) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1682 | || diag(<<' EOF'); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1683 | TEST:<blat_config> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1684 | TEST: - MyConfig.pm replaced by Config.pm | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1685 | TEST: - This test will fail if you change Config.pm and | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1686 | TEST: dont update reference copies used in test comparision. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1689 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1690 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1691 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1692 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 1693 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1694 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1695 | 1 | ▶ | sub blat_myconfig { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blat_myconfig: called CC=11 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1696 | 0 | my $rc ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | 3 | my $myconfig_file_dir = "$ENV{'HOME'}/.ncustom/NCustom"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | 1 | my $myconfig_file = "$myconfig_file_dir/MyConfig.pm"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1699 | 1 | my $global_config_file = "dummy" ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1700 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1701 | # ensure target directory exists | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1702 | 2 | ▶ | if( ! -e $myconfig_file_dir){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1703 | 2 | $rc = mkpath $myconfig_file_dir; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1704 | 2 | ▶ | unless($rc){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1705 | 1 | carp "blat_myconfig: couldnt create $myconfig_file_dir: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1706 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1707 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1708 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1709 | 0 | ▶ | if( ! -d $myconfig_file_dir){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1710 | 0 | carp "blat_myconfig: not at directory: $myconfig_file_dir"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1711 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1713 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1714 | # find source file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1715 | 0 | foreach my $i (@INC){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 1716 | 0 | ▶ | if(-e "$i/NCustom/Config.pm"){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1717 | 2 | $global_config_file = "$i/NCustom/Config.pm"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1718 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1719 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1720 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1721 | 2 | ▶ | if( $global_config_file =~ /^dummy$/){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1722 | 2 | carp "blat_myconfig: cant find global Config.pm file"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1723 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1725 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1726 | # copy file, without pod doco past end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1727 | 0 | $rc = open(SRCFILE, "< $global_config_file"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1728 | 0 | ▶ | unless($rc){carp "blat_myconfig: open $global_config_file : $!"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1729 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1730 | 0 | $rc = open(NEWFILE, "> ${myconfig_file}"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1731 | 0 | ▶ | unless($rc){carp "blat_myconfig: open ${myconfig_file}: $!"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1732 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1733 | 0 | ▶ | while(<SRCFILE>){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1734 | 0 | ▶ | /^__END__/ && last; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1735 | 1 | print NEWFILE $_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1737 | 126 | close(SRCFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1738 | 124 | close(NEWFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1739 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1740 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1741 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1742 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1743 | # config_edit | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1744 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1745 | =item C<config_edit> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1746 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1747 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1748 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1749 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1750 | 1 | ▶ | can_ok("NCustom", qw(config_edit)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1751 | || diag("TEST:<config_edit> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1752 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1753 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1754 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1755 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1756 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1757 | 1 | config_edit((src_fqdn => '"install.baneharbinger.com"', | |||||||||||||||||||||||||||||||||||||||||||||||
| 1758 | test_url1 => '"install.baneharbinger.com/index.html"')); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1759 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1760 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1761 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1762 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1763 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1764 | Config_edit is followed by name vaule pairs. If there is a corresponding name in the personal configuration file, then its vaule shall be updated. If there is no corresponding name then the name value shall be added to the end of the file. If there is no file it shall be created. The personal configuration file is "~/.ncustom/NCustom/MyConfig.pm". | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1765 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1766 | If some configuration vlaues are defined in terms of other configuration values, then the order may be important. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1767 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1768 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1769 | =for example_testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1770 | 1 | my @lines ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1771 | 1 | open(MYCFG, "< $output/.ncustom/NCustom/MyConfig.pm"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1772 | 1 | @lines = <MYCFG>; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1773 | 1 | close(MYCFG); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1774 | 1 | ▶ | ok( grep( /src_fqdn.*install.baneharbinger.com/, @lines) > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1775 | || diag("TEST:<config_edit> can edit(add) src_fqdn"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1776 | 1 | ▶ | ok( grep( /test_url1.*install.baneharbinger.com/, @lines) > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1777 | || diag("TEST:<config_edit> can edit(add) test_url1"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1778 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1779 | 1 | &NCustom::blat_myconfig(); #TODO# hmmm tests should be independent | |||||||||||||||||||||||||||||||||||||||||||||||
| 1780 | 1 | &NCustom::config_edit((test_data1 => "wow", test_data2 => "whoopee doo")); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1781 | 1 | open(MYCFG, "< $output/.ncustom/NCustom/MyConfig.pm"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1782 | 1 | @lines = <MYCFG>; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1783 | 1 | close(MYCFG); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1784 | 1 | ▶ | ok( grep( /test_data1.*wow/, @lines) > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1785 | || diag("TEST:<config_edit> can edit(change) test_data1"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1786 | 1 | ▶ | ok( grep( /test_data2.*whoopee doo/, @lines) > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1787 | || diag("TEST:<config_edit> can edit(change) test_data2"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1788 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1789 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1790 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1791 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1792 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 1793 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1794 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1795 | 1 | ▶ | sub config_edit { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_edit: called CC=15 SCAR=28.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1796 | 1 | my (%config_edit) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1797 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1798 | 1 | my ($rc, $name, $value) ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1799 | 1 | my $myconfig_file_dir = "$ENV{'HOME'}/.ncustom/NCustom"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1800 | 1 | my $myconfig_file = "$myconfig_file_dir/MyConfig.pm"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1801 | 2 | my $global_config_file = "dummy" ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1802 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1803 | # ensure target directory exists | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1804 | 2 | ▶ | if( ! -e $myconfig_file_dir){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1805 | 2 | $rc = mkpath $myconfig_file_dir; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1806 | 2 | ▶ | unless($rc){ carp "config_edit: mkpath $myconfig_file_dir: $!"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1807 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1808 | 0 | ▶ | if( ! -d $myconfig_file_dir){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1809 | 0 | carp "config_edit: not at directory: $myconfig_file_dir"; return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1811 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1812 | # create blank personal config file if there isnt one | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1813 | 0 | ▶ | if( ! -e $myconfig_file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1814 | 0 | $rc = open(NEWFILE, ">$myconfig_file"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1815 | 2 | ▶ | unless($rc){carp "config_edit: open $myconfig_file: $!"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1816 | 0 | my $content = <<' EOF' ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1817 | package NCustom ; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1818 | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1819 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1820 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1821 | 0 | print NEWFILE $content ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1822 | 1 | close(NEWFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1823 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1824 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1825 | # open files for editting | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1826 | 1 | $rc = open(OLDFILE, "< ${myconfig_file}"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1827 | 1 | ▶ | unless($rc){carp "config_edit: open ${myconfig_file}: $!"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1828 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1829 | 0 | $rc = open(NEWFILE, "> ${myconfig_file}.new"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1830 | 0 | ▶ | unless($rc){carp "config_edit: open ${myconfig_file}.new: $!"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1831 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1832 | # do options that are already in the file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1833 | 0 | ▶ | while(<OLDFILE>){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1834 | 0 | my $line = $_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1835 | 2 | my $line_replaced = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1836 | 1 | ▶ | next if($line =~ /^\s*1;/) ; # we will add it back on later | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1837 | 65 | ▶ | while(($name, $value) = each(%config_edit)) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1838 | 65 | ▶ | if($line =~ /^\s*\$Config{.$name.}/ ){ #TODO#nasty pattern assumptions!!! | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1839 | 1 | #print NEWFILE "\$Config{\'$name\'} = \"$value\" ; \n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1840 | 1 | print NEWFILE "\$Config{\'$name\'} = $value ; \n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1841 | 37 | $line_replaced = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1842 | 2 | delete($config_edit{$name}); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1843 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1844 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1845 | 2 | ▶ | print NEWFILE $line unless $line_replaced ; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1846 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1847 | 2 | close(OLDFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1848 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1849 | # do options that were not in the file | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1850 | 63 | ▶ | while(($name, $value) = each(%config_edit)) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1851 | #print NEWFILE "\$Config{\'$name\'} = \"$value\" ;\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1852 | 2 | print NEWFILE "\$Config{\'$name\'} = $value ;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1853 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1854 | 2 | print NEWFILE "1;\n"; # we said we would add it back later | |||||||||||||||||||||||||||||||||||||||||||||||
| 1855 | 2 | close(NEWFILE); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1856 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1857 | # all done | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1858 | 2 | $rc = move("${myconfig_file}.new", "${myconfig_file}"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1859 | 2 | ▶ | unless($rc){carp "config_edit: move $!"; return 0; } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1860 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1861 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1863 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1864 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1865 | # ncustom | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1866 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1867 | =item C<ncustom> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1868 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1869 | =begin example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1870 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1871 | 1 | test_reset(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1872 | 1 | ▶ | can_ok("NCustom", qw(ncustom)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1873 | || diag("TEST:<ncustom> is a public function of NCustom"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1874 | 1 | copy("$input/test1.ncus", "$output"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1875 | 1 | chmod(0750,"$output/test1.ncus"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1876 | 1 | copy("$input/test2.ncus", "$output"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1877 | 1 | chmod(0750,"$output/test2.ncus"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1878 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1879 | =end example | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1880 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1881 | =for example begin | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1882 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1883 | 1 | ncustom(<<' EOF'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1884 | ~/test1.ncus | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1885 | test2.ncus | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1886 | EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1887 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1888 | =for example end | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1889 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1890 | Ncustom is passed one or more filenames, either local filenames or URLs. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1891 | The filenames are assumed to be NCustom scripts, are fetched, and executed. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1892 | If the filename is not an NCustom script, then transactions will not be journalled, and will not be able to be undone. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1893 | An unqualified NCustom script name will be searched for in pwd and the location(s) specified in NCustom::Config. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1894 | URLs will be fetched using the get_url subrouting in NCustom::Config. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1895 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1896 | =for example_testing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1897 | 1 | open(STUBSLOG, "< $output/stubs.log"); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1898 | 1 | my @lines = <STUBSLOG>; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1899 | 1 | close(STUBSLOG); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1900 | 1 | ▶ | ok( grep( /NCustom test1.ncus/, @lines) > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1901 | || diag("TEST:<ncustom> fetches and executes file 1/2"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1902 | 1 | ▶ | ok( grep( /NCustom test2.ncus/, @lines) > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1903 | || diag("TEST:<ncustom> fetches and executes file 2/2"); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1904 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1905 | 1 | output(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1906 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1907 | 1 | =cut | |||||||||||||||||||||||||||||||||||||||||||||||
| 1908 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1909 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1910 | 1 | ▶ | sub ncustom { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ncustom: called CC=14 SCAR=30.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1911 | 0 | my ($file_list, @rest) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1912 | 1 | my $status = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1913 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1914 | #tag# | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1915 | 1 | my @lines = split(/\n/,$file_list); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1916 | 1 | foreach my $line (@lines){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 1917 | 1 | my $executed = 0; #we must invoked something for a line | |||||||||||||||||||||||||||||||||||||||||||||||
| 1918 | 1 | chomp $line ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1919 | 2 | $line =~ s/^\s+//; #trim leading whitespace | |||||||||||||||||||||||||||||||||||||||||||||||
| 1920 | 2 | ▶ | next if $line =~ /^#/; #TODO# comments need much work | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1921 | 2 | ▶ | if(ncustom_try_dir($line, "")){$executed = 1} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1922 | 2 | ▶ | if($executed){next} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1923 | 2 | ▶ | if(ncustom_try_url($line, "")){$executed = 1} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1924 | 0 | ▶ | if($executed){next} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1925 | 1 | my $src_arraryref = $NCustom::Config{'default_src'}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1926 | 0 | foreach my $src (@$src_arraryref){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 1927 | 1 | ▶ | my $dir = (glob($src))[0]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1928 | 1 | ▶ | if(-d $dir){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1929 | 1 | ▶ | if(ncustom_try_dir($line, $dir)){$executed = 1} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1930 | 1 | ▶ | if($executed){last}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1931 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1932 | 1 | ▶ | if(ncustom_try_url($line, $src)){$executed = 1} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1933 | 0 | ▶ | if($executed){last}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1934 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1935 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1936 | 0 | ▶ | if($executed){next} | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1937 | 1 | carp "ncustom: cant find/execute \"$line\".\n"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1938 | 1 | $status = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1939 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1940 | 0 | return $status; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1941 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1942 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1943 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1944 | 3 | ▶ | sub ncustom_try_dir { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ncustom_try_dir: called CC=6 SCAR=18.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1945 | 0 | my ($line, $prefix, @rest) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1946 | 1 | my (@candidates, $candidate); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1947 | 3 | my $executed = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1948 | 3 | my $rc ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1949 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1950 | 3 | @candidates = glob($line); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1951 | 3 | foreach $candidate (@candidates){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 1952 | 3 | my $file = (glob("${prefix}${candidate}"))[0]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1953 | 3 | ▶ | if(-f $file && -x $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $file and -x $file
MC/DC50%1/2
-f $file and -x $file
-f $file
-x $file
Truth table66%2/3
A and B
A= -f $fileB= -x $file
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1954 | 3 | ▶ | if( basename($file) eq $file){ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1955 | 3 | $file = "./$file"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1956 | # so system call ok in this scenario (regardless of pwd being in path) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1957 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1958 | 2 | $rc = system($file); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1959 | 0 | ▶ | carp "ncustom_try_dir: system call=$file : error=$?\n" unless $rc == 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1960 | 2 | $executed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1961 | #for better or worse... | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1962 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1963 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1964 | 2 | return $executed; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1965 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1966 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1967 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1968 | 1 | ▶ | sub ncustom_try_url { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ncustom_try_url: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1969 | 2 | my ($line, $prefix, @rest) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1970 | 3 | my (@candidates, $candidate); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1971 | 1 | my $executed = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1972 | 1 | my $rc ; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1973 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1974 | 1 | my $stagedir = tempdir( DIR => $Config{'tmp_dir'}); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1975 | #TODO# add CLEANUP => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1976 | 1 | my $subref = $NCustom::Config{'get_url'}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1977 | 1 | &$subref("${prefix}${line}",$stagedir); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1978 | 1 | opendir(DIR, $stagedir); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1979 | 1 | ▶ | @candidates = grep { -f $_ && -x $_ } # executable files only | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
-f $_ && -x $_
MC/DC0%0/2
-f $_ && -x $_
-f $_
-x $_
Truth table33%1/3
A && B
A= -f $_B= -x $_
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1980 | 1 | map { "$stagedir/$_" } # form: "path/filename" | |||||||||||||||||||||||||||||||||||||||||||||||
| 1981 | readdir(DIR); # all files | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1982 | 2 | foreach $candidate (@candidates){ | |||||||||||||||||||||||||||||||||||||||||||||||
| 1983 | 2 | $rc = system($candidate); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1984 | 1 | ▶ | carp "ncustom_try_url: system call=${candidate}: error=$?\n" unless $rc ==0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1985 | 0 | $executed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1986 | #for better or worse... | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1987 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1988 | 0 | return $executed; | |||||||||||||||||||||||||||||||||||||||||||||||
| 1989 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1990 | #==================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1991 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1992 | # /////////////////////////////////////////////////////////////////// | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1993 | #<< CC: Constructor <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1994 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 1995 | 2 | constructor(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1996 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1997 | 18 | ▶ | sub constructor { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
constructor: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 1998 | 0 | load_config(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 1999 | 1 | apply_config(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 2000 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2001 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 2002 | # /////////////////////////////////////////////////////////////////// | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2003 | #<< DD: Destructor <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2004 | # \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2005 | # Dont clean up on exit of tests, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2006 | # or we would have nothing to diagnose upon failure of tests, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2007 | # instead we prevent polution by doing a cleanup prior to each test, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2008 | # this is also better as destructor isnt 100% reliable, depending upon death. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2009 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 2010 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 2011 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||