| 1 | package Sys::Config::Manage::Scripts; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use base 'Error::Helper'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use String::ShellQuote; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Term::CallEditor qw/solicit/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | Sys::Config::Manage::Scripts - Allows scripts to be stored specifically for a configuration directory. | ||||||||||
| 13 | |||||||||||
| 14 | =head1 VERSION | ||||||||||
| 15 | |||||||||||
| 16 | Version 0.1.0 | ||||||||||
| 17 | |||||||||||
| 18 | =cut | ||||||||||
| 19 | |||||||||||
| 20 | 2 | our $VERSION = '0.1.0'; | |||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||
| 24 | |||||||||||
| 25 | use Sys::Config::Manage::Scripts; | ||||||||||
| 26 | |||||||||||
| 27 | my $foo = Sys::Config::Manage::Scripts->new(); | ||||||||||
| 28 | ... | ||||||||||
| 29 | |||||||||||
| 30 | =head1 METHODS | ||||||||||
| 31 | |||||||||||
| 32 | =head2 new | ||||||||||
| 33 | |||||||||||
| 34 | $foo=Sys::Config::Manage::Perms->new(\%args); | ||||||||||
| 35 | if($foo->error){ | ||||||||||
| 36 | warn('error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | =cut | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub new{ | ||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 42 | 0 | my %args; | |||||||||
| 43 | 0 | ▶ | if(defined($_[1])){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | %args= %{$_[1]}; | |||||||||
| 45 | }; | ||||||||||
| 46 | 0 | my $method='new'; | |||||||||
| 47 | |||||||||||
| 48 | 0 | my $self = { | |||||||||
| 49 | module=>'Sys-Config-Manage-Scripts', | ||||||||||
| 50 | perror=>undef, | ||||||||||
| 51 | error=>undef, | ||||||||||
| 52 | errorString=>"", | ||||||||||
| 53 | }; | ||||||||||
| 54 | 0 | bless $self; | |||||||||
| 55 | |||||||||||
| 56 | #make sure we have a Sys::Config::Manage | ||||||||||
| 57 | 0 | ▶ | if(!defined( $args{scm} ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | $self->{perror}=1; | |||||||||
| 59 | 0 | $self->{error}=1; | |||||||||
| 60 | 0 | $self->{errorString}='Nothing passed for the Sys::Config::Manage object'; | |||||||||
| 61 | 0 | $self->warn; | |||||||||
| 62 | 0 | return $self; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | #make sure that it is really a Sys::Config::Manage object | ||||||||||
| 66 | 0 | ▶ | if( ref( $args{scm} ) ne "Sys::Config::Manage" ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $self->{perror}=1; | |||||||||
| 68 | 0 | $self->{error}=2; | |||||||||
| 69 | 0 | $self->{errorString}='$args{scm} is not a Sys::Config::Manage object'; | |||||||||
| 70 | 0 | $self->warn; | |||||||||
| 71 | 0 | return $self; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | $self->{scm}=$args{scm}; | |||||||||
| 75 | |||||||||||
| 76 | 0 | return $self; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | =head2 editScript | ||||||||||
| 80 | |||||||||||
| 81 | =cut | ||||||||||
| 82 | |||||||||||
| 83 | 0 | ▶ | sub editScript{ | ||||||||
|
Subroutine
editScript: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||
| 84 | 0 | my $self=$_[0]; | |||||||||
| 85 | 0 | my $configDir=$_[1]; | |||||||||
| 86 | 0 | my $script=$_[2]; | |||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | if( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 0 | return undef; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | #make sure a script is specified | ||||||||||
| 93 | 0 | ▶ | if(!defined($script)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | $self->{error}=7; | |||||||||
| 95 | 0 | $self->{errorString}='No script specified'; | |||||||||
| 96 | 0 | $self->warn; | |||||||||
| 97 | 0 | return undef; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | #make sure that it does not contain a forward slash | ||||||||||
| 101 | 0 | ▶ | if ( $script =~ /\// ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 0 | $self->{error}=10; | |||||||||
| 103 | 0 | $self->{errorString}='The script name,"'.$script.'", contains a forward slash.'; | |||||||||
| 104 | 0 | $self->warn; | |||||||||
| 105 | 0 | return undef; | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | #make sure we have a directory to use | ||||||||||
| 109 | 0 | ▶ | if (!defined($configDir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||
| 111 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | 0 | $self->{error}=3; | |||||||||
| 113 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||
| 114 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 115 | 0 | $self->warn; | |||||||||
| 116 | 0 | return undef; | |||||||||
| 117 | } | ||||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | #make sure the config directory is valid | ||||||||||
| 121 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||
| 122 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | $self->{error}=3; | |||||||||
| 124 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||
| 125 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 126 | 0 | $self->warn; | |||||||||
| 127 | 0 | return undef; | |||||||||
| 128 | } | ||||||||||
| 129 | 0 | ▶ | if (defined( $valid )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | 0 | $self->{error}=4; | |||||||||
| 131 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||
| 132 | 0 | $self->warn; | |||||||||
| 133 | 0 | return undef; | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | #makes sure it exists | ||||||||||
| 137 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 138 | 0 | $self->{error}=5; | |||||||||
| 139 | 0 | $self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; | |||||||||
| 140 | 0 | $self->warn; | |||||||||
| 141 | 0 | return undef; | |||||||||
| 142 | } | ||||||||||
| 143 | |||||||||||
| 144 | 0 | my $scriptFile=$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts/'.$script; | |||||||||
| 145 | |||||||||||
| 146 | #error if it does not exist | ||||||||||
| 147 | 0 | my $data=''; | |||||||||
| 148 | 0 | ▶ | if( -f $scriptFile ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | 0 | my $fh; | |||||||||
| 150 | 0 | ▶ | if ( ! open( $fh, '<', $scriptFile ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 151 | 0 | $self->{error}=11; | |||||||||
| 152 | 0 | $self->{errorString}='Failed to open "'.$scriptFile.'" for reading'; | |||||||||
| 153 | 0 | $self->warn; | |||||||||
| 154 | 0 | return undef; | |||||||||
| 155 | } | ||||||||||
| 156 | 0 | $data=join('', <$fh>); | |||||||||
| 157 | 0 | close $fh; | |||||||||
| 158 | } | ||||||||||
| 159 | |||||||||||
| 160 | 0 | my $fh=solicit($data); | |||||||||
| 161 | 0 | $data=join( '', <$fh> ); | |||||||||
| 162 | 0 | close( $fh ); | |||||||||
| 163 | |||||||||||
| 164 | 0 | $self->writeScript( $configDir, $script, $data ); | |||||||||
| 165 | 0 | ▶ | if ( $self->error ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 166 | 0 | $self->warnString('Failed to write the script out'); | |||||||||
| 167 | 0 | return undef; | |||||||||
| 168 | } | ||||||||||
| 169 | |||||||||||
| 170 | 0 | return 1; | |||||||||
| 171 | } | ||||||||||
| 172 | |||||||||||
| 173 | =head2 getScript | ||||||||||
| 174 | |||||||||||
| 175 | This returns the contents of the specified script. | ||||||||||
| 176 | |||||||||||
| 177 | Two arguments are taken. The first and optional one is the | ||||||||||
| 178 | configuration directory, which if not specified it will be | ||||||||||
| 179 | automatically choosen. The second and required is the | ||||||||||
| 180 | script name. | ||||||||||
| 181 | |||||||||||
| 182 | my $data=$foo->getScript( $configDir, $script ); | ||||||||||
| 183 | if($foo->error){ | ||||||||||
| 184 | warn('error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 185 | } | ||||||||||
| 186 | |||||||||||
| 187 | =cut | ||||||||||
| 188 | |||||||||||
| 189 | 0 | ▶ | sub getScript{ | ||||||||
|
Subroutine
getScript: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||
| 190 | 0 | my $self=$_[0]; | |||||||||
| 191 | 0 | my $configDir=$_[1]; | |||||||||
| 192 | 0 | my $script=$_[2]; | |||||||||
| 193 | |||||||||||
| 194 | 0 | ▶ | if( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 195 | 0 | return undef; | |||||||||
| 196 | } | ||||||||||
| 197 | |||||||||||
| 198 | #make sure a script is specified | ||||||||||
| 199 | 0 | ▶ | if(!defined($script)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 200 | 0 | $self->{error}=7; | |||||||||
| 201 | 0 | $self->{errorString}='No script specified'; | |||||||||
| 202 | 0 | $self->warn; | |||||||||
| 203 | 0 | return undef; | |||||||||
| 204 | } | ||||||||||
| 205 | |||||||||||
| 206 | #make sure that it does not contain a forward slash | ||||||||||
| 207 | 0 | ▶ | if ( $script =~ /\// ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 208 | 0 | $self->{error}=10; | |||||||||
| 209 | 0 | $self->{errorString}='The script name,"'.$script.'", contains a forward slash.'; | |||||||||
| 210 | 0 | $self->warn; | |||||||||
| 211 | 0 | return undef; | |||||||||
| 212 | } | ||||||||||
| 213 | |||||||||||
| 214 | #make sure we have a directory to use | ||||||||||
| 215 | 0 | ▶ | if (!defined($configDir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 216 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||
| 217 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 218 | 0 | $self->{error}=3; | |||||||||
| 219 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||
| 220 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 221 | 0 | $self->warn; | |||||||||
| 222 | 0 | return undef; | |||||||||
| 223 | } | ||||||||||
| 224 | } | ||||||||||
| 225 | |||||||||||
| 226 | #make sure the config directory is valid | ||||||||||
| 227 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||
| 228 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 229 | 0 | $self->{error}=3; | |||||||||
| 230 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||
| 231 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 232 | 0 | $self->warn; | |||||||||
| 233 | 0 | return undef; | |||||||||
| 234 | } | ||||||||||
| 235 | 0 | ▶ | if (defined( $valid )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 236 | 0 | $self->{error}=4; | |||||||||
| 237 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||
| 238 | 0 | $self->warn; | |||||||||
| 239 | 0 | return undef; | |||||||||
| 240 | } | ||||||||||
| 241 | |||||||||||
| 242 | #makes sure it exists | ||||||||||
| 243 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 244 | 0 | $self->{error}=5; | |||||||||
| 245 | 0 | $self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; | |||||||||
| 246 | 0 | $self->warn; | |||||||||
| 247 | 0 | return undef; | |||||||||
| 248 | } | ||||||||||
| 249 | |||||||||||
| 250 | 0 | my $scriptFile=$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts/'.$script; | |||||||||
| 251 | |||||||||||
| 252 | #error if it does not exist | ||||||||||
| 253 | 0 | ▶ | if( ! -f $scriptFile ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 254 | 0 | $self->{error}=12; | |||||||||
| 255 | 0 | $self->{errorString}='The script, "'.$script.'"("'.$scriptFile.'"), does not exist'; | |||||||||
| 256 | 0 | $self->warn; | |||||||||
| 257 | 0 | return undef; | |||||||||
| 258 | } | ||||||||||
| 259 | |||||||||||
| 260 | #open it for reading | ||||||||||
| 261 | 0 | my $fh; | |||||||||
| 262 | 0 | ▶ | if ( ! open( $fh, '<', $scriptFile ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 263 | 0 | $self->{error}=11; | |||||||||
| 264 | 0 | $self->{errorString}='Failed to open "'.$scriptFile.'" for reading'; | |||||||||
| 265 | 0 | $self->warn; | |||||||||
| 266 | 0 | return undef; | |||||||||
| 267 | } | ||||||||||
| 268 | 0 | my $data=join('', <$fh>); | |||||||||
| 269 | 0 | close $fh; | |||||||||
| 270 | |||||||||||
| 271 | 0 | return $data; | |||||||||
| 272 | } | ||||||||||
| 273 | |||||||||||
| 274 | =head2 listScripts | ||||||||||
| 275 | |||||||||||
| 276 | This lists the scripts for the configuration directory in question. | ||||||||||
| 277 | |||||||||||
| 278 | my @scripts=$foo->listScripts($configDir); | ||||||||||
| 279 | if ( $foo->error ){ | ||||||||||
| 280 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 281 | } | ||||||||||
| 282 | |||||||||||
| 283 | =cut | ||||||||||
| 284 | |||||||||||
| 285 | 0 | ▶ | sub listScripts{ | ||||||||
|
Subroutine
listScripts: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||
| 286 | 0 | my $self=$_[0]; | |||||||||
| 287 | 0 | my $configDir=$_[1]; | |||||||||
| 288 | |||||||||||
| 289 | 0 | ▶ | if( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 290 | 0 | return undef; | |||||||||
| 291 | } | ||||||||||
| 292 | |||||||||||
| 293 | #make sure we have a directory to use | ||||||||||
| 294 | 0 | ▶ | if (!defined($configDir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 295 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||
| 296 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 297 | 0 | $self->{error}=3; | |||||||||
| 298 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||
| 299 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 300 | 0 | $self->warn; | |||||||||
| 301 | 0 | return undef; | |||||||||
| 302 | } | ||||||||||
| 303 | } | ||||||||||
| 304 | |||||||||||
| 305 | #make sure the config directory is valid | ||||||||||
| 306 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||
| 307 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 308 | 0 | $self->{error}=3; | |||||||||
| 309 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||
| 310 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 311 | 0 | $self->warn; | |||||||||
| 312 | 0 | return undef; | |||||||||
| 313 | } | ||||||||||
| 314 | 0 | ▶ | if (defined( $valid )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 315 | 0 | $self->{error}=4; | |||||||||
| 316 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||
| 317 | 0 | $self->warn; | |||||||||
| 318 | 0 | return undef; | |||||||||
| 319 | } | ||||||||||
| 320 | |||||||||||
| 321 | #makes sure it exists | ||||||||||
| 322 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 323 | 0 | $self->{error}=5; | |||||||||
| 324 | 0 | $self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; | |||||||||
| 325 | 0 | $self->warn; | |||||||||
| 326 | 0 | return undef; | |||||||||
| 327 | } | ||||||||||
| 328 | |||||||||||
| 329 | #the script directory | ||||||||||
| 330 | 0 | my $scriptDir=$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts/'; | |||||||||
| 331 | |||||||||||
| 332 | #return undef if the script directory does not exist | ||||||||||
| 333 | 0 | ▶ | if (! -d $scriptDir ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 334 | 0 | return undef; | |||||||||
| 335 | } | ||||||||||
| 336 | |||||||||||
| 337 | #read the directory | ||||||||||
| 338 | 0 | my $fh; | |||||||||
| 339 | 0 | ▶ | if(! opendir( $fh, $scriptDir ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 340 | 0 | $self->{error}=6; | |||||||||
| 341 | 0 | $self->{errorString}='Unable to open the script directory, "'.$scriptDir.'",'; | |||||||||
| 342 | 0 | $self->warn; | |||||||||
| 343 | 0 | return undef; | |||||||||
| 344 | } | ||||||||||
| 345 | 0 | my @dirEntries=readdir($fh); | |||||||||
| 346 | 0 | closedir($fh); | |||||||||
| 347 | |||||||||||
| 348 | #only interested in files | ||||||||||
| 349 | 0 | my @toreturn; | |||||||||
| 350 | 0 | my $int=0; | |||||||||
| 351 | 0 | ▶ | while(defined($dirEntries[$int])){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 352 | 0 | ▶ | if( -f $scriptDir.'/'.$dirEntries[$int] ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 353 | 0 | push(@toreturn, $dirEntries[$int]); | |||||||||
| 354 | } | ||||||||||
| 355 | |||||||||||
| 356 | 0 | $int++; | |||||||||
| 357 | } | ||||||||||
| 358 | |||||||||||
| 359 | 0 | return @toreturn; | |||||||||
| 360 | } | ||||||||||
| 361 | |||||||||||
| 362 | =head2 scriptExists | ||||||||||
| 363 | |||||||||||
| 364 | This verifies that the script in question exists. | ||||||||||
| 365 | |||||||||||
| 366 | Two arguments are taken. The first is the configuration | ||||||||||
| 367 | directory and if not specified it will be choosen | ||||||||||
| 368 | automatically. The second is the script name. | ||||||||||
| 369 | |||||||||||
| 370 | my $exists=$foo->scriptExists($configDir, $script); | ||||||||||
| 371 | if( $foo->error ){ | ||||||||||
| 372 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 373 | }else{ | ||||||||||
| 374 | if( $exists ){ | ||||||||||
| 375 | print "It exists\n"; | ||||||||||
| 376 | }else | ||||||||||
| 377 | print "It does not exists\n"; | ||||||||||
| 378 | } | ||||||||||
| 379 | } | ||||||||||
| 380 | |||||||||||
| 381 | =cut | ||||||||||
| 382 | |||||||||||
| 383 | 0 | ▶ | sub scriptExists{ | ||||||||
|
Subroutine
scriptExists: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||
| 384 | 0 | my $self=$_[0]; | |||||||||
| 385 | 0 | my $configDir=$_[1]; | |||||||||
| 386 | 0 | my $script=$_[2]; | |||||||||
| 387 | |||||||||||
| 388 | 0 | ▶ | if( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 389 | 0 | return undef; | |||||||||
| 390 | } | ||||||||||
| 391 | |||||||||||
| 392 | 0 | ▶ | if(!defined($script)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 393 | 0 | $self->{error}=7; | |||||||||
| 394 | 0 | $self->{errorString}='No script specified'; | |||||||||
| 395 | 0 | $self->warn; | |||||||||
| 396 | 0 | return undef; | |||||||||
| 397 | } | ||||||||||
| 398 | |||||||||||
| 399 | #make sure we have a directory to use | ||||||||||
| 400 | 0 | ▶ | if (!defined($configDir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 401 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||
| 402 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 403 | 0 | $self->{error}=3; | |||||||||
| 404 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||
| 405 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 406 | 0 | $self->warn; | |||||||||
| 407 | 0 | return undef; | |||||||||
| 408 | } | ||||||||||
| 409 | } | ||||||||||
| 410 | |||||||||||
| 411 | #make sure the config directory is valid | ||||||||||
| 412 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||
| 413 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 414 | 0 | $self->{error}=3; | |||||||||
| 415 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||
| 416 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 417 | 0 | $self->warn; | |||||||||
| 418 | 0 | return undef; | |||||||||
| 419 | } | ||||||||||
| 420 | 0 | ▶ | if (defined( $valid )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 421 | 0 | $self->{error}=4; | |||||||||
| 422 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||
| 423 | 0 | $self->warn; | |||||||||
| 424 | 0 | return undef; | |||||||||
| 425 | } | ||||||||||
| 426 | |||||||||||
| 427 | #makes sure it exists | ||||||||||
| 428 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 429 | 0 | $self->{error}=5; | |||||||||
| 430 | 0 | $self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; | |||||||||
| 431 | 0 | $self->warn; | |||||||||
| 432 | 0 | return undef; | |||||||||
| 433 | } | ||||||||||
| 434 | |||||||||||
| 435 | 0 | ▶ | if( -f $self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts/'.$script ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 436 | 0 | return 1; | |||||||||
| 437 | } | ||||||||||
| 438 | |||||||||||
| 439 | 0 | return undef; | |||||||||
| 440 | } | ||||||||||
| 441 | |||||||||||
| 442 | =head2 readScript | ||||||||||
| 443 | |||||||||||
| 444 | This reads a script and returns it's contents. | ||||||||||
| 445 | |||||||||||
| 446 | The arguments are taken. The fist is the name of the configuration | ||||||||||
| 447 | directory and it not specified it will be automarically choosen. | ||||||||||
| 448 | The second is the script name. | ||||||||||
| 449 | |||||||||||
| 450 | my $contents=$foo->readScript( $configDir, $script ); | ||||||||||
| 451 | if( $foo->error ){ | ||||||||||
| 452 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 453 | } | ||||||||||
| 454 | |||||||||||
| 455 | =cut | ||||||||||
| 456 | |||||||||||
| 457 | 0 | ▶ | sub readScript{ | ||||||||
|
Subroutine
readScript: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||
| 458 | 0 | my $self=$_[0]; | |||||||||
| 459 | 0 | my $configDir=$_[1]; | |||||||||
| 460 | 0 | my $script=$_[2]; | |||||||||
| 461 | |||||||||||
| 462 | 0 | ▶ | if( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 463 | 0 | return undef; | |||||||||
| 464 | } | ||||||||||
| 465 | |||||||||||
| 466 | 0 | ▶ | if(!defined($script)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 467 | 0 | $self->{error}=7; | |||||||||
| 468 | 0 | $self->{errorString}='No script specified'; | |||||||||
| 469 | 0 | $self->warn; | |||||||||
| 470 | 0 | return undef; | |||||||||
| 471 | } | ||||||||||
| 472 | |||||||||||
| 473 | #make sure we have a directory to use | ||||||||||
| 474 | 0 | ▶ | if (!defined($configDir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 475 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||
| 476 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 477 | 0 | $self->{error}=3; | |||||||||
| 478 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||
| 479 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 480 | 0 | $self->warn; | |||||||||
| 481 | 0 | return undef; | |||||||||
| 482 | } | ||||||||||
| 483 | } | ||||||||||
| 484 | |||||||||||
| 485 | #make sure the config directory is valid | ||||||||||
| 486 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||
| 487 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 488 | 0 | $self->{error}=3; | |||||||||
| 489 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||
| 490 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 491 | 0 | $self->warn; | |||||||||
| 492 | 0 | return undef; | |||||||||
| 493 | } | ||||||||||
| 494 | 0 | ▶ | if (defined( $valid )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 495 | 0 | $self->{error}=4; | |||||||||
| 496 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||
| 497 | 0 | $self->warn; | |||||||||
| 498 | 0 | return undef; | |||||||||
| 499 | } | ||||||||||
| 500 | |||||||||||
| 501 | #makes sure the configuration directory exists | ||||||||||
| 502 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 503 | 0 | $self->{error}=5; | |||||||||
| 504 | 0 | $self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; | |||||||||
| 505 | 0 | $self->warn; | |||||||||
| 506 | 0 | return undef; | |||||||||
| 507 | } | ||||||||||
| 508 | |||||||||||
| 509 | 0 | my $scriptFile=$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts/'.$script; | |||||||||
| 510 | |||||||||||
| 511 | #error if it does not exist | ||||||||||
| 512 | 0 | ▶ | if( ! -f $scriptFile ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 513 | 0 | $self->{error}=12; | |||||||||
| 514 | 0 | $self->{errorString}='The script, "'.$script.'"("'.$scriptFile.'"), does not exist'; | |||||||||
| 515 | 0 | $self->warn; | |||||||||
| 516 | 0 | return undef; | |||||||||
| 517 | } | ||||||||||
| 518 | |||||||||||
| 519 | 0 | my $fh; | |||||||||
| 520 | 0 | ▶ | if( ! open( $fh, '<', $scriptFile ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 521 | 0 | $self->{error}=11; | |||||||||
| 522 | 0 | $self->{errorString}='The script, "'.$script.'"("'.$scriptFile.'"), could not be opened '; | |||||||||
| 523 | 0 | $self->warn; | |||||||||
| 524 | 0 | return undef; | |||||||||
| 525 | } | ||||||||||
| 526 | 0 | my $contents=join('', <$fh>); | |||||||||
| 527 | 0 | close($fh); | |||||||||
| 528 | |||||||||||
| 529 | 0 | return $contents; | |||||||||
| 530 | } | ||||||||||
| 531 | |||||||||||
| 532 | =head2 runScript | ||||||||||
| 533 | |||||||||||
| 534 | This executes the via system. | ||||||||||
| 535 | |||||||||||
| 536 | The arguments are taken. The fist is the name of the configuration | ||||||||||
| 537 | directory and it not specified it will be automarically choosen. | ||||||||||
| 538 | The second is the script name. | ||||||||||
| 539 | |||||||||||
| 540 | my $exit=$foo->runScript($configDir, $script); | ||||||||||
| 541 | if( $foo->error ){ | ||||||||||
| 542 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 543 | } | ||||||||||
| 544 | |||||||||||
| 545 | =cut | ||||||||||
| 546 | |||||||||||
| 547 | 0 | ▶ | sub runScript{ | ||||||||
|
Subroutine
runScript: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||
| 548 | 0 | my $self=$_[0]; | |||||||||
| 549 | 0 | my $configDir=$_[1]; | |||||||||
| 550 | 0 | my $script=$_[2]; | |||||||||
| 551 | |||||||||||
| 552 | 0 | ▶ | if( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 553 | 0 | return undef; | |||||||||
| 554 | } | ||||||||||
| 555 | |||||||||||
| 556 | 0 | ▶ | if(!defined($script)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 557 | 0 | $self->{error}=7; | |||||||||
| 558 | 0 | $self->{errorString}='No script specified'; | |||||||||
| 559 | 0 | $self->warn; | |||||||||
| 560 | 0 | return undef; | |||||||||
| 561 | } | ||||||||||
| 562 | |||||||||||
| 563 | #make sure we have a directory to use | ||||||||||
| 564 | 0 | ▶ | if (!defined($configDir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 565 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||
| 566 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 567 | 0 | $self->{error}=3; | |||||||||
| 568 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||
| 569 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 570 | 0 | $self->warn; | |||||||||
| 571 | 0 | return undef; | |||||||||
| 572 | } | ||||||||||
| 573 | } | ||||||||||
| 574 | |||||||||||
| 575 | #make sure the config directory is valid | ||||||||||
| 576 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||
| 577 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 578 | 0 | $self->{error}=3; | |||||||||
| 579 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||
| 580 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 581 | 0 | $self->warn; | |||||||||
| 582 | 0 | return undef; | |||||||||
| 583 | } | ||||||||||
| 584 | 0 | ▶ | if (defined( $valid )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 585 | 0 | $self->{error}=4; | |||||||||
| 586 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||
| 587 | 0 | $self->warn; | |||||||||
| 588 | 0 | return undef; | |||||||||
| 589 | } | ||||||||||
| 590 | |||||||||||
| 591 | #makes sure it exists | ||||||||||
| 592 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 593 | 0 | $self->{error}=5; | |||||||||
| 594 | 0 | $self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; | |||||||||
| 595 | 0 | $self->warn; | |||||||||
| 596 | 0 | return undef; | |||||||||
| 597 | } | ||||||||||
| 598 | |||||||||||
| 599 | 0 | my $scriptFile=$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts/'.$script; | |||||||||
| 600 | |||||||||||
| 601 | #error if it does not exist | ||||||||||
| 602 | 0 | ▶ | if( ! -f $scriptFile ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 603 | 0 | $self->{error}=12; | |||||||||
| 604 | 0 | $self->{errorString}='The script, "'.$script.'"("'.$scriptFile.'"), does not exist'; | |||||||||
| 605 | 0 | $self->warn; | |||||||||
| 606 | 0 | return undef; | |||||||||
| 607 | } | ||||||||||
| 608 | |||||||||||
| 609 | 0 | system($scriptFile); | |||||||||
| 610 | |||||||||||
| 611 | 0 | return $?<<8; | |||||||||
| 612 | } | ||||||||||
| 613 | |||||||||||
| 614 | =head2 writeScript | ||||||||||
| 615 | |||||||||||
| 616 | This writes a script. If it does not exist, it will be created. | ||||||||||
| 617 | |||||||||||
| 618 | Three arguments are taken. The first is the configuration directory, | ||||||||||
| 619 | the second is the script name, and the third is the contents of the script. | ||||||||||
| 620 | |||||||||||
| 621 | If the configuration directory is not specified, it will be automaticaly choosen. | ||||||||||
| 622 | |||||||||||
| 623 | $foo->writeScript($configDir, $scriptName, $scriptContents); | ||||||||||
| 624 | if( $foo->error ){ | ||||||||||
| 625 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 626 | } | ||||||||||
| 627 | |||||||||||
| 628 | =cut | ||||||||||
| 629 | |||||||||||
| 630 | 0 | ▶ | sub writeScript{ | ||||||||
|
Subroutine
writeScript: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||
| 631 | 0 | my $self=$_[0]; | |||||||||
| 632 | 0 | my $configDir=$_[1]; | |||||||||
| 633 | 0 | my $script=$_[2]; | |||||||||
| 634 | 0 | my $data=$_[3]; | |||||||||
| 635 | |||||||||||
| 636 | 0 | ▶ | if( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 637 | 0 | return undef; | |||||||||
| 638 | } | ||||||||||
| 639 | |||||||||||
| 640 | 0 | ▶ | if(!defined($script)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 641 | 0 | $self->{error}=7; | |||||||||
| 642 | 0 | $self->{errorString}='No script name specified'; | |||||||||
| 643 | 0 | $self->warn; | |||||||||
| 644 | 0 | return undef; | |||||||||
| 645 | } | ||||||||||
| 646 | |||||||||||
| 647 | 0 | ▶ | if ( $script =~ /\// ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 648 | 0 | $self->{error}=10; | |||||||||
| 649 | 0 | $self->{errorString}='The script name,"'.$script.'", contains a forward slash.'; | |||||||||
| 650 | 0 | $self->warn; | |||||||||
| 651 | 0 | return undef; | |||||||||
| 652 | } | ||||||||||
| 653 | |||||||||||
| 654 | 0 | ▶ | if(!defined($data)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 655 | 0 | $self->{error}=8; | |||||||||
| 656 | 0 | $self->{errorString}='Nothing specified for the script'; | |||||||||
| 657 | 0 | $self->warn; | |||||||||
| 658 | 0 | return undef; | |||||||||
| 659 | } | ||||||||||
| 660 | |||||||||||
| 661 | #make sure we have a directory to use | ||||||||||
| 662 | 0 | ▶ | if (!defined($configDir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 663 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||
| 664 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 665 | 0 | $self->{error}=3; | |||||||||
| 666 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||
| 667 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 668 | 0 | $self->warn; | |||||||||
| 669 | 0 | return undef; | |||||||||
| 670 | } | ||||||||||
| 671 | } | ||||||||||
| 672 | |||||||||||
| 673 | #make sure the config directory is valid | ||||||||||
| 674 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||
| 675 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 676 | 0 | $self->{error}=3; | |||||||||
| 677 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||
| 678 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||
| 679 | 0 | $self->warn; | |||||||||
| 680 | 0 | return undef; | |||||||||
| 681 | } | ||||||||||
| 682 | 0 | ▶ | if (defined( $valid )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 683 | 0 | $self->{error}=4; | |||||||||
| 684 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||
| 685 | 0 | $self->warn; | |||||||||
| 686 | 0 | return undef; | |||||||||
| 687 | } | ||||||||||
| 688 | |||||||||||
| 689 | #makes sure it exists | ||||||||||
| 690 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 691 | 0 | $self->{error}=5; | |||||||||
| 692 | 0 | $self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; | |||||||||
| 693 | 0 | $self->warn; | |||||||||
| 694 | 0 | return undef; | |||||||||
| 695 | } | ||||||||||
| 696 | |||||||||||
| 697 | #make sure the script directory exists | ||||||||||
| 698 | 0 | ▶ | if( ! -d $self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/' ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 699 | 0 | ▶ | if(!mkdir( $self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage' )){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 700 | 0 | $self->{error}=9; | |||||||||
| 701 | 0 | $self->{errorString}='"'.$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/'.'" could not be created'; | |||||||||
| 702 | 0 | $self->warn; | |||||||||
| 703 | 0 | return undef; | |||||||||
| 704 | } | ||||||||||
| 705 | } | ||||||||||
| 706 | 0 | ▶ | if( ! -d $self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts/' ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 707 | 0 | ▶ | if(!mkdir( $self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts' )){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 708 | 0 | $self->{error}=9; | |||||||||
| 709 | 0 | $self->{errorString}='"'.$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts" could not be created'; | |||||||||
| 710 | 0 | $self->warn; | |||||||||
| 711 | 0 | return undef; | |||||||||
| 712 | } | ||||||||||
| 713 | } | ||||||||||
| 714 | |||||||||||
| 715 | 0 | my $file=$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Scripts/'.$script; | |||||||||
| 716 | |||||||||||
| 717 | #check if it exists already or not | ||||||||||
| 718 | 0 | my $exists=0; | |||||||||
| 719 | 0 | ▶ | if( -e $file ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 720 | 0 | $exists=1; | |||||||||
| 721 | } | ||||||||||
| 722 | |||||||||||
| 723 | 0 | my $fh; | |||||||||
| 724 | 0 | ▶ | if( ! open( $fh, '>', $file ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 725 | 0 | $self->{error}=11; | |||||||||
| 726 | 0 | $self->{errorString}='"'.$file.'" could not be opened for writing'; | |||||||||
| 727 | 0 | $self->warn; | |||||||||
| 728 | 0 | return undef; | |||||||||
| 729 | } | ||||||||||
| 730 | 0 | print $fh $data; | |||||||||
| 731 | 0 | close($fh); | |||||||||
| 732 | |||||||||||
| 733 | 0 | chmod( oct('0774'), $file ); | |||||||||
| 734 | |||||||||||
| 735 | #add it if it, if it did not exist previously | ||||||||||
| 736 | 0 | ▶ | if ( ! $exists ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 737 | 0 | ▶ | if (defined( $self->{scm}->{addCommand} )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 738 | 0 | my $command=$self->{scm}->{addCommand}; | |||||||||
| 739 | 0 | my $newfile=shell_quote($file); | |||||||||
| 740 | |||||||||||
| 741 | 0 | $command=~s/\%\%\%file\%\%\%/$newfile/g; | |||||||||
| 742 | 0 | system($command); | |||||||||
| 743 | 0 | my $exit = $?<<8; | |||||||||
| 744 | 0 | ▶ | if ($exit ne '0') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 745 | 0 | $self->{error}=16; | |||||||||
| 746 | 0 | $self->{errorString}='The add command failed. command="'.$command.'" exit="'.$exit.'"'; | |||||||||
| 747 | 0 | $self->warn; | |||||||||
| 748 | 0 | return undef; | |||||||||
| 749 | } | ||||||||||
| 750 | } | ||||||||||
| 751 | } | ||||||||||
| 752 | |||||||||||
| 753 | 0 | return 1; | |||||||||
| 754 | } | ||||||||||
| 755 | |||||||||||
| 756 | =head1 ERROR CODES | ||||||||||
| 757 | |||||||||||
| 758 | =head2 1 | ||||||||||
| 759 | |||||||||||
| 760 | Nothing passed for the Sys::Config::Manage object. | ||||||||||
| 761 | |||||||||||
| 762 | =head2 2 | ||||||||||
| 763 | |||||||||||
| 764 | $args{scm} is not a Sys::Config::Manage object. | ||||||||||
| 765 | |||||||||||
| 766 | =head2 3 | ||||||||||
| 767 | |||||||||||
| 768 | Sys::Config::Manage errored. | ||||||||||
| 769 | |||||||||||
| 770 | =head2 4 | ||||||||||
| 771 | |||||||||||
| 772 | Invalid configuration directory name. | ||||||||||
| 773 | |||||||||||
| 774 | =head2 5 | ||||||||||
| 775 | |||||||||||
| 776 | The specified configuration directory does not exist. | ||||||||||
| 777 | |||||||||||
| 778 | =head2 6 | ||||||||||
| 779 | |||||||||||
| 780 | Unable to open the script directory. | ||||||||||
| 781 | |||||||||||
| 782 | =head2 7 | ||||||||||
| 783 | |||||||||||
| 784 | No script specified. | ||||||||||
| 785 | |||||||||||
| 786 | =head2 8 | ||||||||||
| 787 | |||||||||||
| 788 | No script data specified. | ||||||||||
| 789 | |||||||||||
| 790 | =head2 9 | ||||||||||
| 791 | |||||||||||
| 792 | Unable to create a required directory. | ||||||||||
| 793 | |||||||||||
| 794 | =head2 10 | ||||||||||
| 795 | |||||||||||
| 796 | The script name contains a '/'. | ||||||||||
| 797 | |||||||||||
| 798 | =head2 11 | ||||||||||
| 799 | |||||||||||
| 800 | Could not open the script. | ||||||||||
| 801 | |||||||||||
| 802 | =head2 12 | ||||||||||
| 803 | |||||||||||
| 804 | The script does not exist. | ||||||||||
| 805 | |||||||||||
| 806 | =head1 AUTHOR | ||||||||||
| 807 | |||||||||||
| 808 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||
| 809 | |||||||||||
| 810 | =head1 BUGS | ||||||||||
| 811 | |||||||||||
| 812 | Please report any bugs or feature requests to C<bug-sys-config-manage-perms at rt.cpan.org>, or through | ||||||||||
| 813 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sys-Config-Manage-Perms>. I will be notified, and then you'll | ||||||||||
| 814 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 815 | |||||||||||
| 816 | =head1 SUPPORT | ||||||||||
| 817 | |||||||||||
| 818 | You can find documentation for this module with the perldoc command. | ||||||||||
| 819 | |||||||||||
| 820 | perldoc Sys::Config::Manage::Perms | ||||||||||
| 821 | |||||||||||
| 822 | |||||||||||
| 823 | You can also look for information at: | ||||||||||
| 824 | |||||||||||
| 825 | =over 4 | ||||||||||
| 826 | |||||||||||
| 827 | =item * RT: CPAN's request tracker | ||||||||||
| 828 | |||||||||||
| 829 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Config-Manage> | ||||||||||
| 830 | |||||||||||
| 831 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 832 | |||||||||||
| 833 | L<http://annocpan.org/dist/Sys-Config-Manage> | ||||||||||
| 834 | |||||||||||
| 835 | =item * CPAN Ratings | ||||||||||
| 836 | |||||||||||
| 837 | L<http://cpanratings.perl.org/d/Sys-Config-Manage> | ||||||||||
| 838 | |||||||||||
| 839 | =item * Search CPAN | ||||||||||
| 840 | |||||||||||
| 841 | L<http://search.cpan.org/dist/Sys-Config-Manage/> | ||||||||||
| 842 | |||||||||||
| 843 | =back | ||||||||||
| 844 | |||||||||||
| 845 | |||||||||||
| 846 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 847 | |||||||||||
| 848 | |||||||||||
| 849 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 850 | |||||||||||
| 851 | Copyright 2011 Zane C. Bowers-Hadley. | ||||||||||
| 852 | |||||||||||
| 853 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 854 | under the terms of either: the GNU General Public License as published | ||||||||||
| 855 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 856 | |||||||||||
| 857 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 858 | |||||||||||
| 859 | |||||||||||
| 860 | =cut | ||||||||||
| 861 | |||||||||||
| 862 | 2 | 1; # End of Sys::Config::Manage::Scripts | |||||||||