| 1 | package Toader::Templates; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use Toader::isaToaderDir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use Cwd 'abs_path'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use base 'Error::Helper'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use Text::Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | ▶ | use Toader::Templates::Defaults; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | Toader::Templates - This handles fetching Toader templates. | ||||||||||
| 14 | |||||||||||
| 15 | =head1 VERSION | ||||||||||
| 16 | |||||||||||
| 17 | Version 1.0.0 | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | 5 | our $VERSION = '1.0.0'; | |||||||||
| 22 | |||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||
| 24 | |||||||||||
| 25 | For information on the storage and rendering of entries, | ||||||||||
| 26 | please see 'Documentation/Templates.pod'. | ||||||||||
| 27 | |||||||||||
| 28 | =head1 METHODS | ||||||||||
| 29 | |||||||||||
| 30 | =head2 new | ||||||||||
| 31 | |||||||||||
| 32 | =head3 args hash ref | ||||||||||
| 33 | |||||||||||
| 34 | =head4 dir | ||||||||||
| 35 | |||||||||||
| 36 | This is the directory to intiate in. | ||||||||||
| 37 | |||||||||||
| 38 | =head4 toader | ||||||||||
| 39 | |||||||||||
| 40 | This is a L<Toader> object. | ||||||||||
| 41 | |||||||||||
| 42 | my $foo = Toader::Templates->new( \%args ); | ||||||||||
| 43 | if($foo->error){ | ||||||||||
| 44 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | =cut | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub new{ | ||||||||
|
Subroutine
new: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||
| 50 | 0 | my %args; | |||||||||
| 51 | 0 | ▶ | if(defined($_[1])){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | %args= %{$_[1]}; | |||||||||
| 53 | }; | ||||||||||
| 54 | |||||||||||
| 55 | 0 | my $self={ | |||||||||
| 56 | error=>undef, | ||||||||||
| 57 | errorString=>'', | ||||||||||
| 58 | perror=>undef, | ||||||||||
| 59 | isatd=>Toader::isaToaderDir->new(), | ||||||||||
| 60 | dir=>undef, | ||||||||||
| 61 | defaults=>Toader::Templates::Defaults->new, | ||||||||||
| 62 | errorExtra=>{ | ||||||||||
| 63 | flags=>{ | ||||||||||
| 64 | 1=>'noDirSpecified', | ||||||||||
| 65 | 2=>'isaToaderDirErrored', | ||||||||||
| 66 | 3=>'notAtoaderDir', | ||||||||||
| 67 | 4=>'invalidTemplateName', | ||||||||||
| 68 | 5=>'openTemplateFailed', | ||||||||||
| 69 | 6=>'noDefaultTemplate', | ||||||||||
| 70 | 7=>'templateFillErrored', | ||||||||||
| 71 | 8=>'templateStringUndef', | ||||||||||
| 72 | 9=>'templateNameUndef', | ||||||||||
| 73 | 10=>'notAtoaderObj', | ||||||||||
| 74 | 11=>'getVCSerrored', | ||||||||||
| 75 | 12=>'VCSusableErrored', | ||||||||||
| 76 | 13=>'noTemplateSpecified', | ||||||||||
| 77 | 14=>'underVCSerrored', | ||||||||||
| 78 | 15=>'VCSaddErrored', | ||||||||||
| 79 | 16=>'VCSdeleteErrored', | ||||||||||
| 80 | 17=>'unlinkFailed', | ||||||||||
| 81 | 18=>'notInDir', | ||||||||||
| 82 | 19=>'noToaderObj', | ||||||||||
| 83 | }, | ||||||||||
| 84 | }, | ||||||||||
| 85 | VCSusable=>0, | ||||||||||
| 86 | }; | ||||||||||
| 87 | 0 | bless $self; | |||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | if ( defined( $args{dir} ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | ▶ | if ( ! $self->{isatd}->isaToaderDir( $args{dir} ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | $self->{perror}=1; | |||||||||
| 92 | $self->{error}=1, | ||||||||||
| 93 | 0 | $self->{errorString}='The specified directory is not a Toader directory'; | |||||||||
| 94 | 0 | $self->warn; | |||||||||
| 95 | 0 | return $self; | |||||||||
| 96 | } | ||||||||||
| 97 | 0 | $self->{dir}=$args{dir}; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | #if we have a Toader object, reel it in | ||||||||||
| 101 | 0 | ▶ | if ( ! defined( $args{toader} ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 0 | $self->{error}=19; | |||||||||
| 103 | 0 | $self->{perror}=1; | |||||||||
| 104 | 0 | $self->{errorString}='No $args{toader} specified'; | |||||||||
| 105 | 0 | $self->warn; | |||||||||
| 106 | 0 | return $self; | |||||||||
| 107 | } | ||||||||||
| 108 | 0 | ▶ | if ( ref( $args{toader} ) ne "Toader" ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 0 | $self->{perror}=1; | |||||||||
| 110 | 0 | $self->{error}=10; | |||||||||
| 111 | 0 | $self->{errorString}='The object specified is a "'.ref($args{toader}).'"'; | |||||||||
| 112 | 0 | $self->warn; | |||||||||
| 113 | 0 | return $self; | |||||||||
| 114 | } | ||||||||||
| 115 | 0 | $self->{toader}=$args{toader}; | |||||||||
| 116 | |||||||||||
| 117 | #gets the Toader::VCS object | ||||||||||
| 118 | 0 | $self->{vcs}=$self->{toader}->getVCS; | |||||||||
| 119 | 0 | ▶ | if ( $self->{toader}->error ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | 0 | $self->{perror}=1; | |||||||||
| 121 | 0 | $self->{error}=11; | |||||||||
| 122 | $self->{errorString}='Toader->getVCS errored. error="'. | ||||||||||
| 123 | 0 | $self->{toader}->error.'" errorString="'.$self->{toader}->errorString.'"'; | |||||||||
| 124 | 0 | $self->warn; | |||||||||
| 125 | 0 | return $self; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | #checks if VCS is usable | ||||||||||
| 129 | 0 | $self->{VCSusable}=$self->{vcs}->usable; | |||||||||
| 130 | 0 | ▶ | if ( $self->{vcs}->error ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | 0 | $self->{perror}=1; | |||||||||
| 132 | 0 | $self->{error}=12; | |||||||||
| 133 | $self->{errorString}='Toader::VCS->usable errored. error="'. | ||||||||||
| 134 | 0 | $self->{toader}->error.'" errorString="'.$self->{toader}->errorString.'"'; | |||||||||
| 135 | 0 | $self->warn; | |||||||||
| 136 | 0 | return $self; | |||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | 0 | return $self; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | =head2 dirGet | ||||||||||
| 143 | |||||||||||
| 144 | This gets L<Toader> directory this entry is associated with. | ||||||||||
| 145 | |||||||||||
| 146 | This will only error if a permanent error is set. | ||||||||||
| 147 | |||||||||||
| 148 | my $dir=$foo->dirGet; | ||||||||||
| 149 | if($foo->error){ | ||||||||||
| 150 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 151 | } | ||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||
| 154 | |||||||||||
| 155 | 0 | ▶ | sub dirGet{ | ||||||||
|
Subroutine
dirGet: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 156 | 0 | my $self=$_[0]; | |||||||||
| 157 | |||||||||||
| 158 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | 0 | return undef; | |||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | 0 | return $self->{dir}; | |||||||||
| 163 | } | ||||||||||
| 164 | |||||||||||
| 165 | =head2 dirSet | ||||||||||
| 166 | |||||||||||
| 167 | This sets L<Toader> directory this entry is associated with. | ||||||||||
| 168 | |||||||||||
| 169 | One argument is taken and it is the L<Toader> directory to set it to. | ||||||||||
| 170 | |||||||||||
| 171 | $foo->dirSet($toaderDirectory); | ||||||||||
| 172 | if($foo->error){ | ||||||||||
| 173 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 174 | } | ||||||||||
| 175 | |||||||||||
| 176 | =cut | ||||||||||
| 177 | |||||||||||
| 178 | 0 | ▶ | sub dirSet{ | ||||||||
|
Subroutine
dirSet: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 179 | 0 | my $self=$_[0]; | |||||||||
| 180 | 0 | my $dir=$_[1]; | |||||||||
| 181 | |||||||||||
| 182 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 183 | 0 | return undef; | |||||||||
| 184 | } | ||||||||||
| 185 | |||||||||||
| 186 | #checks if the directory is Toader directory or not | ||||||||||
| 187 | 0 | my $returned=$self->{isatd}->isaToaderDir($dir); | |||||||||
| 188 | 0 | ▶ | if (! $returned ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 189 | 0 | $self->{error}=1; | |||||||||
| 190 | 0 | $self->{errorString}='"'.$dir.'" is not a Toader directory'; | |||||||||
| 191 | 0 | $self->warn; | |||||||||
| 192 | 0 | return undef; | |||||||||
| 193 | } | ||||||||||
| 194 | |||||||||||
| 195 | 0 | $self->{dir}=$dir; | |||||||||
| 196 | |||||||||||
| 197 | 0 | return 1; | |||||||||
| 198 | } | ||||||||||
| 199 | |||||||||||
| 200 | =head2 fill_in | ||||||||||
| 201 | |||||||||||
| 202 | This fills in a template that has been passed to it. | ||||||||||
| 203 | |||||||||||
| 204 | Two arguments are taken. The first is the template name. | ||||||||||
| 205 | The second is a hash reference. | ||||||||||
| 206 | |||||||||||
| 207 | The returned string is the filled out template. | ||||||||||
| 208 | |||||||||||
| 209 | my $rendered=$foo->fill_in( $templateName, \%hash ); | ||||||||||
| 210 | if ( $foo->error ){ | ||||||||||
| 211 | warn( 'Error:'.$foo->error.': '.$foo->errorString ); | ||||||||||
| 212 | } | ||||||||||
| 213 | |||||||||||
| 214 | =cut | ||||||||||
| 215 | |||||||||||
| 216 | 0 | ▶ | sub fill_in{ | ||||||||
|
Subroutine
fill_in: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 217 | 0 | my $self=$_[0]; | |||||||||
| 218 | 0 | my $name=$_[1]; | |||||||||
| 219 | 0 | my $hash=$_[2]; | |||||||||
| 220 | |||||||||||
| 221 | 0 | ▶ | if( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 222 | 0 | return undef; | |||||||||
| 223 | } | ||||||||||
| 224 | |||||||||||
| 225 | #make sure a template name is specified | ||||||||||
| 226 | 0 | ▶ | if ( ! defined( $name ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 227 | 0 | $self->{error}=9; | |||||||||
| 228 | 0 | $self->{errorString}='No template name specified'; | |||||||||
| 229 | 0 | $self->warn; | |||||||||
| 230 | 0 | return undef; | |||||||||
| 231 | } | ||||||||||
| 232 | |||||||||||
| 233 | #gets the template | ||||||||||
| 234 | 0 | my $template=$self->getTemplate( $name ); | |||||||||
| 235 | 0 | ▶ | if ( $self->error ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 236 | 0 | return undef; | |||||||||
| 237 | } | ||||||||||
| 238 | |||||||||||
| 239 | 0 | return $self->fill_in_string( $template, $hash ); | |||||||||
| 240 | } | ||||||||||
| 241 | |||||||||||
| 242 | =head2 fill_in_string | ||||||||||
| 243 | |||||||||||
| 244 | This fills in a template that has been passed to it. | ||||||||||
| 245 | |||||||||||
| 246 | Two arguments are required and the first is the template string to use and | ||||||||||
| 247 | second it is the hash to pass to it. | ||||||||||
| 248 | |||||||||||
| 249 | The returned string is the filled out template. | ||||||||||
| 250 | |||||||||||
| 251 | my $rendered=$foo->fill_in_string( $templateString, \%hash ); | ||||||||||
| 252 | if ( $foo->error ){ | ||||||||||
| 253 | warn( 'Error:'.$foo->error.': '.$foo->errorString ); | ||||||||||
| 254 | } | ||||||||||
| 255 | |||||||||||
| 256 | =cut | ||||||||||
| 257 | |||||||||||
| 258 | 0 | ▶ | sub fill_in_string{ | ||||||||
|
Subroutine
fill_in_string: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 259 | 0 | my $self=$_[0]; | |||||||||
| 260 | 0 | my $string=$_[1]; | |||||||||
| 261 | 0 | my $hash=$_[2]; | |||||||||
| 262 | |||||||||||
| 263 | 0 | ▶ | if( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 264 | 0 | return undef; | |||||||||
| 265 | } | ||||||||||
| 266 | |||||||||||
| 267 | 0 | ▶ | if ( ! defined( $string ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 268 | 0 | $self->{error}=8; | |||||||||
| 269 | 0 | $self->{errorString}='No template string specified'; | |||||||||
| 270 | 0 | $self->warn; | |||||||||
| 271 | 0 | return undef; | |||||||||
| 272 | } | ||||||||||
| 273 | |||||||||||
| 274 | 0 | my $template = Text::Template->new( | |||||||||
| 275 | TYPE => 'STRING', | ||||||||||
| 276 | SOURCE => $string, | ||||||||||
| 277 | DELIMITERS=>[ '[==', '==]' ], | ||||||||||
| 278 | ); | ||||||||||
| 279 | |||||||||||
| 280 | 0 | my $rendered=$template->fill_in( | |||||||||
| 281 | HASH=>$hash, | ||||||||||
| 282 | ); | ||||||||||
| 283 | |||||||||||
| 284 | 0 | ▶ | if ( ! defined ( $rendered ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 285 | 0 | $self->{error}=7; | |||||||||
| 286 | 0 | $self->{errorString}='Error encountered filling in the template'; | |||||||||
| 287 | 0 | $self->warn; | |||||||||
| 288 | 0 | return undef; | |||||||||
| 289 | } | ||||||||||
| 290 | |||||||||||
| 291 | 0 | return $rendered; | |||||||||
| 292 | } | ||||||||||
| 293 | |||||||||||
| 294 | =head2 findTemplate | ||||||||||
| 295 | |||||||||||
| 296 | This finds a specified template. | ||||||||||
| 297 | |||||||||||
| 298 | One arguement is taken and it is the name of the template. | ||||||||||
| 299 | |||||||||||
| 300 | A return of undef can mean either a error or it was not found. | ||||||||||
| 301 | If there was an error, the method error will return true. | ||||||||||
| 302 | |||||||||||
| 303 | my $templateFile=$foo->findTemplate($templateName); | ||||||||||
| 304 | if( !defined( $templateFile ) ){ | ||||||||||
| 305 | if($foo->error){ | ||||||||||
| 306 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 307 | }else{ | ||||||||||
| 308 | print("Not found\n"); | ||||||||||
| 309 | } | ||||||||||
| 310 | }else{ | ||||||||||
| 311 | print $templateFile."\n"; | ||||||||||
| 312 | } | ||||||||||
| 313 | |||||||||||
| 314 | =cut | ||||||||||
| 315 | |||||||||||
| 316 | 0 | ▶ | sub findTemplate{ | ||||||||
|
Subroutine
findTemplate: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||
| 317 | 0 | my $self=$_[0]; | |||||||||
| 318 | 0 | my $name=$_[1]; | |||||||||
| 319 | |||||||||||
| 320 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 321 | 0 | return undef; | |||||||||
| 322 | } | ||||||||||
| 323 | |||||||||||
| 324 | #make sure a directory has been set | ||||||||||
| 325 | 0 | ▶ | if (!defined( $self->{dir} )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 326 | 0 | $self->{error}=2; | |||||||||
| 327 | 0 | $self->{errorString}='No directory has been set yet'; | |||||||||
| 328 | 0 | $self->warn; | |||||||||
| 329 | 0 | return undef; | |||||||||
| 330 | } | ||||||||||
| 331 | |||||||||||
| 332 | #checks if the name is valid | ||||||||||
| 333 | 0 | my $returned=$self->templateNameCheck($name); | |||||||||
| 334 | 0 | ▶ | if (! $returned ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 335 | 0 | $self->{error}=4; | |||||||||
| 336 | 0 | $self->{errorString}='"'.$name.'" is not a valid template name'; | |||||||||
| 337 | 0 | $self->warn; | |||||||||
| 338 | 0 | return undef; | |||||||||
| 339 | } | ||||||||||
| 340 | |||||||||||
| 341 | #checks if the directory is Toader directory or not | ||||||||||
| 342 | 0 | $returned=$self->{isatd}->isaToaderDir( $self->{dir} ); | |||||||||
| 343 | 0 | ▶ | if (! $returned ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 344 | 0 | $self->{error}=3; | |||||||||
| 345 | 0 | $self->{errorString}='"'.$self->{dir}.'" is no longer a Toader directory'; | |||||||||
| 346 | 0 | $self->warn; | |||||||||
| 347 | 0 | return undef; | |||||||||
| 348 | } | ||||||||||
| 349 | |||||||||||
| 350 | #initial stuff to check | ||||||||||
| 351 | 0 | my $dir=$self->{dir}; | |||||||||
| 352 | 0 | my $template=$dir.'/.toader/templates/'.$name; | |||||||||
| 353 | |||||||||||
| 354 | #checks if the template exists | ||||||||||
| 355 | 0 | ▶ | if (-f $template) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 356 | 0 | return $template; | |||||||||
| 357 | } | ||||||||||
| 358 | |||||||||||
| 359 | #recurse down trying to find the last one | ||||||||||
| 360 | 0 | $dir=abs_path($dir.'/..'); | |||||||||
| 361 | #we will always find something below so it is just set to 1 | ||||||||||
| 362 | 0 | while (1) { | |||||||||
| 363 | #we hit the FS root... | ||||||||||
| 364 | #if he hit this, something is definitely wrong | ||||||||||
| 365 | 0 | ▶ | if ($dir eq '/') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 366 | 0 | return undef; | |||||||||
| 367 | } | ||||||||||
| 368 | |||||||||||
| 369 | #make sure | ||||||||||
| 370 | 0 | $returned=$self->{isatd}->isaToaderDir($dir); | |||||||||
| 371 | 0 | ▶ | if (!$returned) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 372 | 0 | return undef; | |||||||||
| 373 | } | ||||||||||
| 374 | |||||||||||
| 375 | #check if it exists | ||||||||||
| 376 | 0 | $template=$dir.'/.toader/templates/'.$name; | |||||||||
| 377 | 0 | ▶ | if (-f $template) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 378 | 0 | return $template; | |||||||||
| 379 | } | ||||||||||
| 380 | |||||||||||
| 381 | #check the next directory | ||||||||||
| 382 | 0 | $dir=abs_path($dir.'/..'); | |||||||||
| 383 | } | ||||||||||
| 384 | } | ||||||||||
| 385 | |||||||||||
| 386 | =head2 getTemplate | ||||||||||
| 387 | |||||||||||
| 388 | This finds a template and then returns it. | ||||||||||
| 389 | |||||||||||
| 390 | The method findTemplate will be used and if that fails the default | ||||||||||
| 391 | template will be returned. | ||||||||||
| 392 | |||||||||||
| 393 | One arguement is required and it is the template name. | ||||||||||
| 394 | |||||||||||
| 395 | my $template=$foo->getTemplate($templateName); | ||||||||||
| 396 | if($foo->error){ | ||||||||||
| 397 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 398 | } | ||||||||||
| 399 | |||||||||||
| 400 | =cut | ||||||||||
| 401 | |||||||||||
| 402 | 0 | ▶ | sub getTemplate{ | ||||||||
|
Subroutine
getTemplate: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||
| 403 | 0 | my $self=$_[0]; | |||||||||
| 404 | 0 | my $name=$_[1]; | |||||||||
| 405 | |||||||||||
| 406 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 407 | 0 | return undef; | |||||||||
| 408 | } | ||||||||||
| 409 | |||||||||||
| 410 | #make sure a template name is specified | ||||||||||
| 411 | 0 | ▶ | if ( ! defined( $name ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 412 | 0 | $self->{error}=9; | |||||||||
| 413 | 0 | $self->{errorString}='No template name specified'; | |||||||||
| 414 | 0 | $self->warn; | |||||||||
| 415 | 0 | return undef; | |||||||||
| 416 | } | ||||||||||
| 417 | |||||||||||
| 418 | #try to find it as a file | ||||||||||
| 419 | #also allow this to do the error checking as it is the same | ||||||||||
| 420 | 0 | my $file=$self->findTemplate($name); | |||||||||
| 421 | 0 | ▶ | if ($self->error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 422 | 0 | $self->warnString('findTemplate errored'); | |||||||||
| 423 | 0 | return undef; | |||||||||
| 424 | } | ||||||||||
| 425 | |||||||||||
| 426 | #the contents of the template to be returned | ||||||||||
| 427 | 0 | my $template; | |||||||||
| 428 | |||||||||||
| 429 | #if we found a file, read it and return it | ||||||||||
| 430 | 0 | ▶ | if (defined($file)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 431 | 0 | my $fh; | |||||||||
| 432 | 0 | ▶ | if ( ! open( $fh, '<', $file ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 433 | 0 | $self->{error}=5; | |||||||||
| 434 | 0 | $self->{errorString}="Unable to open '".$file."'"; | |||||||||
| 435 | 0 | $self->warn; | |||||||||
| 436 | 0 | return undef; | |||||||||
| 437 | } | ||||||||||
| 438 | 0 | $template=join('',<$fh>); | |||||||||
| 439 | 0 | close $fh; | |||||||||
| 440 | 0 | return $template; | |||||||||
| 441 | } | ||||||||||
| 442 | |||||||||||
| 443 | #tries to fetch the default template | ||||||||||
| 444 | 0 | $template=$self->{defaults}->getTemplate($name); | |||||||||
| 445 | 0 | ▶ | if ( ! defined( $template ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 446 | 0 | $self->{error}=6; | |||||||||
| 447 | 0 | $self->{errorString}='No default template'; | |||||||||
| 448 | 0 | $self->warn; | |||||||||
| 449 | 0 | return undef; | |||||||||
| 450 | } | ||||||||||
| 451 | |||||||||||
| 452 | 0 | return $template; | |||||||||
| 453 | } | ||||||||||
| 454 | |||||||||||
| 455 | =head2 getTemplateDefault | ||||||||||
| 456 | |||||||||||
| 457 | This finds a default template and then returns it. | ||||||||||
| 458 | |||||||||||
| 459 | One arguement is required and it is the template name. | ||||||||||
| 460 | |||||||||||
| 461 | my $template=$foo->getTemplate($templateName); | ||||||||||
| 462 | if($foo->error){ | ||||||||||
| 463 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 464 | } | ||||||||||
| 465 | |||||||||||
| 466 | =cut | ||||||||||
| 467 | |||||||||||
| 468 | 0 | ▶ | sub getTemplateDefault{ | ||||||||
|
Subroutine
getTemplateDefault: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 469 | 0 | my $self=$_[0]; | |||||||||
| 470 | 0 | my $name=$_[1]; | |||||||||
| 471 | |||||||||||
| 472 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 473 | 0 | return undef; | |||||||||
| 474 | } | ||||||||||
| 475 | |||||||||||
| 476 | #make sure a template name is specified | ||||||||||
| 477 | 0 | ▶ | if ( ! defined( $name ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 478 | 0 | $self->{error}=9; | |||||||||
| 479 | 0 | $self->{errorString}='No template name specified'; | |||||||||
| 480 | 0 | $self->warn; | |||||||||
| 481 | 0 | return undef; | |||||||||
| 482 | } | ||||||||||
| 483 | |||||||||||
| 484 | #tries to fetch the default template | ||||||||||
| 485 | 0 | my $template=$self->{defaults}->getTemplate($name); | |||||||||
| 486 | 0 | ▶ | if ( ! defined( $template ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 487 | 0 | $self->{error}=6; | |||||||||
| 488 | 0 | $self->{errorString}='No default template'; | |||||||||
| 489 | 0 | $self->warn; | |||||||||
| 490 | 0 | return undef; | |||||||||
| 491 | } | ||||||||||
| 492 | |||||||||||
| 493 | 0 | return $template; | |||||||||
| 494 | } | ||||||||||
| 495 | |||||||||||
| 496 | =head2 listTemplates | ||||||||||
| 497 | |||||||||||
| 498 | This lists the various templates in the directory. | ||||||||||
| 499 | |||||||||||
| 500 | my @templates=$foo->listTemplates; | ||||||||||
| 501 | if($foo->error){ | ||||||||||
| 502 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 503 | } | ||||||||||
| 504 | |||||||||||
| 505 | =cut | ||||||||||
| 506 | |||||||||||
| 507 | 0 | ▶ | sub listTemplates{ | ||||||||
|
Subroutine
listTemplates: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 508 | 0 | my $self=$_[0]; | |||||||||
| 509 | |||||||||||
| 510 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 511 | 0 | return undef; | |||||||||
| 512 | } | ||||||||||
| 513 | |||||||||||
| 514 | #make sure a directory has been set | ||||||||||
| 515 | 0 | ▶ | if (!defined( $self->{dir} )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 516 | 0 | $self->{error}=2; | |||||||||
| 517 | 0 | $self->{errorString}='No directory has been set yet'; | |||||||||
| 518 | 0 | $self->warn; | |||||||||
| 519 | 0 | return undef; | |||||||||
| 520 | } | ||||||||||
| 521 | |||||||||||
| 522 | #checks if the directory is Toader directory or not | ||||||||||
| 523 | 0 | my $returned=$self->{isatd}->isaToaderDir( $self->{dir} ); | |||||||||
| 524 | 0 | ▶ | if (! $returned ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 525 | 0 | $self->{error}=3; | |||||||||
| 526 | 0 | $self->{errorString}='"'.$self->{dir}.'" is no longer a Toader directory'; | |||||||||
| 527 | 0 | $self->warn; | |||||||||
| 528 | 0 | return undef; | |||||||||
| 529 | } | ||||||||||
| 530 | |||||||||||
| 531 | #the directory to list | ||||||||||
| 532 | 0 | my $dir=$self->{dir}.'/.toader/templates/'; | |||||||||
| 533 | |||||||||||
| 534 | #makes sure the template exists and if it does not, return only having the default | ||||||||||
| 535 | 0 | ▶ | if (! -d $dir) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 536 | 0 | return; | |||||||||
| 537 | } | ||||||||||
| 538 | |||||||||||
| 539 | #lists each theme | ||||||||||
| 540 | 0 | my $dh; | |||||||||
| 541 | 0 | ▶ | if (opendir($dh, $dir )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 542 | 0 | $self->{error}='4'; | |||||||||
| 543 | 0 | $self->{errorString}='Failed to open the directory "'.$dir.'"'; | |||||||||
| 544 | 0 | $self->warn; | |||||||||
| 545 | 0 | return undef; | |||||||||
| 546 | } | ||||||||||
| 547 | 0 | my @templates=grep( { -f $dir.'/'.$_ } readdir($dh) ); | |||||||||
| 548 | 0 | close($dh); | |||||||||
| 549 | |||||||||||
| 550 | 0 | return \@templates; | |||||||||
| 551 | } | ||||||||||
| 552 | |||||||||||
| 553 | =head2 listDefaultTemplates | ||||||||||
| 554 | |||||||||||
| 555 | This lists the various templates in the directory. | ||||||||||
| 556 | |||||||||||
| 557 | my @templates=$foo->listTemplates; | ||||||||||
| 558 | if($foo->error){ | ||||||||||
| 559 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 560 | } | ||||||||||
| 561 | |||||||||||
| 562 | =cut | ||||||||||
| 563 | |||||||||||
| 564 | 0 | ▶ | sub listDefaultTemplates{ | ||||||||
|
Subroutine
listDefaultTemplates: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 565 | 0 | my $self=$_[0]; | |||||||||
| 566 | |||||||||||
| 567 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 568 | 0 | return undef; | |||||||||
| 569 | } | ||||||||||
| 570 | |||||||||||
| 571 | 0 | return $self->{defaults}->listTemplates; | |||||||||
| 572 | } | ||||||||||
| 573 | |||||||||||
| 574 | =head2 remove | ||||||||||
| 575 | |||||||||||
| 576 | This removes a template from the current directory. | ||||||||||
| 577 | |||||||||||
| 578 | One argument is required and that is the name of the template. | ||||||||||
| 579 | |||||||||||
| 580 | $foo->remove( $name ); | ||||||||||
| 581 | if($foo->error){ | ||||||||||
| 582 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 583 | } | ||||||||||
| 584 | |||||||||||
| 585 | =cut | ||||||||||
| 586 | |||||||||||
| 587 | 0 | ▶ | sub remove{ | ||||||||
|
Subroutine
remove: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||
| 588 | 0 | my $self=$_[0]; | |||||||||
| 589 | 0 | my $name=$_[1]; | |||||||||
| 590 | |||||||||||
| 591 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 592 | 0 | return undef; | |||||||||
| 593 | } | ||||||||||
| 594 | |||||||||||
| 595 | #make sure a directory has been set | ||||||||||
| 596 | 0 | ▶ | if (!defined( $self->{dir} )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 597 | 0 | $self->{error}=2; | |||||||||
| 598 | 0 | $self->{errorString}='No directory has been set yet'; | |||||||||
| 599 | 0 | $self->warn; | |||||||||
| 600 | 0 | return undef; | |||||||||
| 601 | } | ||||||||||
| 602 | |||||||||||
| 603 | #make sure a template name is specified | ||||||||||
| 604 | 0 | ▶ | if ( ! defined( $name ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 605 | 0 | $self->{error}=9; | |||||||||
| 606 | 0 | $self->{errorString}='No template name specified'; | |||||||||
| 607 | 0 | $self->warn; | |||||||||
| 608 | 0 | return undef; | |||||||||
| 609 | } | ||||||||||
| 610 | |||||||||||
| 611 | #checks if the name is valid | ||||||||||
| 612 | 0 | my $returned=$self->templateNameCheck($name); | |||||||||
| 613 | 0 | ▶ | if (! $returned ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 614 | 0 | $self->{error}=4; | |||||||||
| 615 | 0 | $self->{errorString}='"'.$name.'" is not a valid template name'; | |||||||||
| 616 | 0 | $self->warn; | |||||||||
| 617 | 0 | return undef; | |||||||||
| 618 | } | ||||||||||
| 619 | |||||||||||
| 620 | #make sure the template is in this directory | ||||||||||
| 621 | 0 | ▶ | if ( ! $self->templateInDir( $name ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 622 | 0 | $self->{error}=18; | |||||||||
| 623 | $self->{errorString}='Template "'.$name.'" is not in "'. | ||||||||||
| 624 | 0 | $self->{dir}.'"'; | |||||||||
| 625 | 0 | $self->warn; | |||||||||
| 626 | 0 | return undef; | |||||||||
| 627 | } | ||||||||||
| 628 | |||||||||||
| 629 | #the file in question | ||||||||||
| 630 | 0 | my $file=$self->{dir}.'/.toader/templates/'.$name; | |||||||||
| 631 | |||||||||||
| 632 | #try to unlink the file | ||||||||||
| 633 | 0 | ▶ | if ( ! unlink( $file ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 634 | 0 | $self->{error}=17; | |||||||||
| 635 | 0 | $self->{errorString}='Unlink of "'.$file.'" failed'; | |||||||||
| 636 | 0 | $self->warn; | |||||||||
| 637 | 0 | return undef; | |||||||||
| 638 | } | ||||||||||
| 639 | |||||||||||
| 640 | #if VCS is not usable, return here | ||||||||||
| 641 | 0 | ▶ | if ( ! $self->{VCSusable} ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 642 | 0 | return 1; | |||||||||
| 643 | } | ||||||||||
| 644 | |||||||||||
| 645 | #if it is not under VCS, we have nothing to do | ||||||||||
| 646 | 0 | my $underVCS=$self->{vcs}->underVCS($file); | |||||||||
| 647 | 0 | ▶ | if ( $self->{vcs}->error ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 648 | 0 | $self->{error}=14; | |||||||||
| 649 | $self->{errorString}='Toader::VCS->underVCS errored. error="'. | ||||||||||
| 650 | 0 | $self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"'; | |||||||||
| 651 | 0 | $self->warn; | |||||||||
| 652 | 0 | return undef; | |||||||||
| 653 | } | ||||||||||
| 654 | 0 | ▶ | if ( $underVCS ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 655 | 0 | return 1; | |||||||||
| 656 | } | ||||||||||
| 657 | |||||||||||
| 658 | #delete it as if we reach here it is not under VCS and VCS is being used | ||||||||||
| 659 | 0 | $self->{vcs}->delete( $file ); | |||||||||
| 660 | 0 | ▶ | if ( $self->{vcs}->error ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 661 | 0 | $self->{error}=16; | |||||||||
| 662 | $self->{errorString}='Toader::VCS->delete errored. error="'. | ||||||||||
| 663 | 0 | $self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"'; | |||||||||
| 664 | 0 | $self->warn; | |||||||||
| 665 | 0 | return undef; | |||||||||
| 666 | } | ||||||||||
| 667 | |||||||||||
| 668 | |||||||||||
| 669 | 0 | return 1; | |||||||||
| 670 | } | ||||||||||
| 671 | |||||||||||
| 672 | =head2 set | ||||||||||
| 673 | |||||||||||
| 674 | This sets a template in the current directory. | ||||||||||
| 675 | |||||||||||
| 676 | Two arguments are required and those in order are the name | ||||||||||
| 677 | template and the template. | ||||||||||
| 678 | |||||||||||
| 679 | $foo->set( $name, $template ); | ||||||||||
| 680 | if($foo->error){ | ||||||||||
| 681 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 682 | } | ||||||||||
| 683 | |||||||||||
| 684 | =cut | ||||||||||
| 685 | |||||||||||
| 686 | 0 | ▶ | sub set{ | ||||||||
|
Subroutine
set: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||
| 687 | 0 | my $self=$_[0]; | |||||||||
| 688 | 0 | my $name=$_[1]; | |||||||||
| 689 | 0 | my $template=$_[2]; | |||||||||
| 690 | |||||||||||
| 691 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 692 | 0 | return undef; | |||||||||
| 693 | } | ||||||||||
| 694 | |||||||||||
| 695 | #make sure a directory has been set | ||||||||||
| 696 | 0 | ▶ | if (!defined( $self->{dir} )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 697 | 0 | $self->{error}=2; | |||||||||
| 698 | 0 | $self->{errorString}='No directory has been set yet'; | |||||||||
| 699 | 0 | $self->warn; | |||||||||
| 700 | 0 | return undef; | |||||||||
| 701 | } | ||||||||||
| 702 | |||||||||||
| 703 | #make sure a template name is specified | ||||||||||
| 704 | 0 | ▶ | if ( ! defined( $name ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 705 | 0 | $self->{error}=9; | |||||||||
| 706 | 0 | $self->{errorString}='No template name specified'; | |||||||||
| 707 | 0 | $self->warn; | |||||||||
| 708 | 0 | return undef; | |||||||||
| 709 | } | ||||||||||
| 710 | |||||||||||
| 711 | #checks if the name is valid | ||||||||||
| 712 | 0 | my $returned=$self->templateNameCheck($name); | |||||||||
| 713 | 0 | ▶ | if (! $returned ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 714 | 0 | $self->{error}=4; | |||||||||
| 715 | 0 | $self->{errorString}='"'.$name.'" is not a valid template name'; | |||||||||
| 716 | 0 | $self->warn; | |||||||||
| 717 | 0 | return undef; | |||||||||
| 718 | } | ||||||||||
| 719 | |||||||||||
| 720 | #make sure a template name is specified | ||||||||||
| 721 | 0 | ▶ | if ( ! defined( $template ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 722 | 0 | $self->{error}=13; | |||||||||
| 723 | 0 | $self->{errorString}='No template specified'; | |||||||||
| 724 | 0 | $self->warn; | |||||||||
| 725 | 0 | return undef; | |||||||||
| 726 | } | ||||||||||
| 727 | |||||||||||
| 728 | #the file in question | ||||||||||
| 729 | 0 | my $file=$self->{dir}.'/.toader/templates/'.$name; | |||||||||
| 730 | |||||||||||
| 731 | #write the template out | ||||||||||
| 732 | 0 | my $fh; | |||||||||
| 733 | 0 | ▶ | if ( ! open( $fh, '>', $file ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 734 | 0 | $self->{error}=5; | |||||||||
| 735 | 0 | $self->{errorString}='Unable to open "'.$file.'" for writing'; | |||||||||
| 736 | 0 | $self->warn; | |||||||||
| 737 | 0 | return undef; | |||||||||
| 738 | } | ||||||||||
| 739 | 0 | print $fh $template; | |||||||||
| 740 | 0 | close $fh; | |||||||||
| 741 | |||||||||||
| 742 | #if VCS is not usable, return here | ||||||||||
| 743 | 0 | ▶ | if ( ! $self->{VCSusable} ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 744 | 0 | return 1; | |||||||||
| 745 | } | ||||||||||
| 746 | |||||||||||
| 747 | #if it is not under VCS, we have nothing to do | ||||||||||
| 748 | 0 | my $underVCS=$self->{vcs}->underVCS($file); | |||||||||
| 749 | 0 | ▶ | if ( $self->{vcs}->error ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 750 | 0 | $self->{error}=14; | |||||||||
| 751 | $self->{errorString}='Toader::VCS->underVCS errored. error="'. | ||||||||||
| 752 | 0 | $self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"'; | |||||||||
| 753 | 0 | $self->warn; | |||||||||
| 754 | 0 | return undef; | |||||||||
| 755 | } | ||||||||||
| 756 | 0 | ▶ | if ( $underVCS ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 757 | 0 | return 1; | |||||||||
| 758 | } | ||||||||||
| 759 | |||||||||||
| 760 | #add it as if we reach here it is not under VCS and VCS is being used | ||||||||||
| 761 | 0 | $self->{vcs}->add( $file ); | |||||||||
| 762 | 0 | ▶ | if ( $self->{vcs}->error ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 763 | 0 | $self->{error}=15; | |||||||||
| 764 | $self->{errorString}='Toader::VCS->add errored. error="'. | ||||||||||
| 765 | 0 | $self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"'; | |||||||||
| 766 | 0 | $self->warn; | |||||||||
| 767 | 0 | return undef; | |||||||||
| 768 | } | ||||||||||
| 769 | |||||||||||
| 770 | 0 | return 1; | |||||||||
| 771 | } | ||||||||||
| 772 | |||||||||||
| 773 | =head2 templateInDir | ||||||||||
| 774 | |||||||||||
| 775 | This checks if the template is in the current directory. | ||||||||||
| 776 | |||||||||||
| 777 | One argument is required and that is the name of the template. | ||||||||||
| 778 | |||||||||||
| 779 | $foo->templateInDir( $name ); | ||||||||||
| 780 | if($foo->error){ | ||||||||||
| 781 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||
| 782 | } | ||||||||||
| 783 | |||||||||||
| 784 | =cut | ||||||||||
| 785 | |||||||||||
| 786 | 0 | ▶ | sub templateInDir{ | ||||||||
|
Subroutine
templateInDir: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 787 | 0 | my $self=$_[0]; | |||||||||
| 788 | 0 | my $name=$_[1]; | |||||||||
| 789 | |||||||||||
| 790 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 791 | 0 | return undef; | |||||||||
| 792 | } | ||||||||||
| 793 | |||||||||||
| 794 | #make sure a directory has been set | ||||||||||
| 795 | 0 | ▶ | if (!defined( $self->{dir} )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 796 | 0 | $self->{error}=2; | |||||||||
| 797 | 0 | $self->{errorString}='No directory has been set yet'; | |||||||||
| 798 | 0 | $self->warn; | |||||||||
| 799 | 0 | return undef; | |||||||||
| 800 | } | ||||||||||
| 801 | |||||||||||
| 802 | #make sure a template name is specified | ||||||||||
| 803 | 0 | ▶ | if ( ! defined( $name ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 804 | 0 | $self->{error}=9; | |||||||||
| 805 | 0 | $self->{errorString}='No template name specified'; | |||||||||
| 806 | 0 | $self->warn; | |||||||||
| 807 | 0 | return undef; | |||||||||
| 808 | } | ||||||||||
| 809 | |||||||||||
| 810 | #checks if the name is valid | ||||||||||
| 811 | 0 | my $returned=$self->templateNameCheck($name); | |||||||||
| 812 | 0 | ▶ | if (! $returned ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 813 | 0 | $self->{error}=4; | |||||||||
| 814 | 0 | $self->{errorString}='"'.$name.'" is not a valid template name'; | |||||||||
| 815 | 0 | $self->warn; | |||||||||
| 816 | 0 | return undef; | |||||||||
| 817 | } | ||||||||||
| 818 | |||||||||||
| 819 | #the file in question | ||||||||||
| 820 | 0 | my $file=$self->{dir}.'/.toader/templates/'.$name; | |||||||||
| 821 | |||||||||||
| 822 | #checks if it exists | ||||||||||
| 823 | 0 | ▶ | if ( -f $file ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 824 | 0 | return 1; | |||||||||
| 825 | } | ||||||||||
| 826 | |||||||||||
| 827 | 0 | return 0; | |||||||||
| 828 | } | ||||||||||
| 829 | |||||||||||
| 830 | =head2 templateNameCheck | ||||||||||
| 831 | |||||||||||
| 832 | This makes sure checks to make sure a template name is valid. | ||||||||||
| 833 | |||||||||||
| 834 | my $returned=$foo->templateNameCheck($name); | ||||||||||
| 835 | if ($returned){ | ||||||||||
| 836 | print "Valid\n"; | ||||||||||
| 837 | } | ||||||||||
| 838 | |||||||||||
| 839 | =cut | ||||||||||
| 840 | |||||||||||
| 841 | 0 | ▶ | sub templateNameCheck{ | ||||||||
|
Subroutine
templateNameCheck: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||
| 842 | 0 | my $self=$_[0]; | |||||||||
| 843 | 0 | my $name=$_[1]; | |||||||||
| 844 | |||||||||||
| 845 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 846 | 0 | return undef; | |||||||||
| 847 | } | ||||||||||
| 848 | |||||||||||
| 849 | 0 | ▶ | if (!defined($name)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 850 | 0 | return 0; | |||||||||
| 851 | } | ||||||||||
| 852 | 0 | ▶ | if ($name =~ /^ /) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 853 | 0 | return 0; | |||||||||
| 854 | } | ||||||||||
| 855 | 0 | ▶ | if ($name =~ /\t/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 856 | 0 | return 0; | |||||||||
| 857 | } | ||||||||||
| 858 | 0 | ▶ | if ($name =~ /\n/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 859 | 0 | return 0; | |||||||||
| 860 | } | ||||||||||
| 861 | 0 | ▶ | if ($name =~ / $/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 862 | 0 | return 0; | |||||||||
| 863 | } | ||||||||||
| 864 | |||||||||||
| 865 | 0 | return 1; | |||||||||
| 866 | } | ||||||||||
| 867 | |||||||||||
| 868 | =head1 ERROR CODES | ||||||||||
| 869 | |||||||||||
| 870 | =head2 1, noDirSpecified | ||||||||||
| 871 | |||||||||||
| 872 | The specified directory is not a L<Toader> directory. | ||||||||||
| 873 | |||||||||||
| 874 | =head2 2, isaToaderDirErrored | ||||||||||
| 875 | |||||||||||
| 876 | No directory has been specified yet. | ||||||||||
| 877 | |||||||||||
| 878 | =head2 3, notAtoaderDir | ||||||||||
| 879 | |||||||||||
| 880 | The directory in question is no longer a toader directory. | ||||||||||
| 881 | |||||||||||
| 882 | =head2 4, invalidTemplateName | ||||||||||
| 883 | |||||||||||
| 884 | Not a valid template name. | ||||||||||
| 885 | |||||||||||
| 886 | =head2 5, openTemplateFailed | ||||||||||
| 887 | |||||||||||
| 888 | Unable to open the template file. | ||||||||||
| 889 | |||||||||||
| 890 | =head2 6, noDefaultTemplate | ||||||||||
| 891 | |||||||||||
| 892 | Unable to fetch the default template. It does not exist. | ||||||||||
| 893 | |||||||||||
| 894 | =head2 7, templateFillErrored | ||||||||||
| 895 | |||||||||||
| 896 | Errored filling out the template string. | ||||||||||
| 897 | |||||||||||
| 898 | =head2 8, templateStringUndef | ||||||||||
| 899 | |||||||||||
| 900 | Nothing specified for the template string. | ||||||||||
| 901 | |||||||||||
| 902 | =head2 9, templateNameUndef | ||||||||||
| 903 | |||||||||||
| 904 | Template name is not defined. | ||||||||||
| 905 | |||||||||||
| 906 | =head2 10, notAtoaderObj | ||||||||||
| 907 | |||||||||||
| 908 | The object in question is not a Toader object. | ||||||||||
| 909 | |||||||||||
| 910 | =head2 11, getVCSerrored | ||||||||||
| 911 | |||||||||||
| 912 | L<Toader>->getVCS errored. | ||||||||||
| 913 | |||||||||||
| 914 | =head2 12, VCSusableErrored | ||||||||||
| 915 | |||||||||||
| 916 | L<Toader::VCS>->usable errored. | ||||||||||
| 917 | |||||||||||
| 918 | =head2 13, noTemplateSpecified | ||||||||||
| 919 | |||||||||||
| 920 | Nothing specified for the data for a template. | ||||||||||
| 921 | |||||||||||
| 922 | =head2 14, underVCSerrored | ||||||||||
| 923 | |||||||||||
| 924 | L<Toader::VCS>->underVCS errored. | ||||||||||
| 925 | |||||||||||
| 926 | =head2 15, VCSaddErrored | ||||||||||
| 927 | |||||||||||
| 928 | L<Toader::VCS>->add errored. | ||||||||||
| 929 | |||||||||||
| 930 | =head2 16, VCSdeleteErrored | ||||||||||
| 931 | |||||||||||
| 932 | L<Toader::VCS>->delete errored. | ||||||||||
| 933 | |||||||||||
| 934 | =head2 17, unlinkFailed | ||||||||||
| 935 | |||||||||||
| 936 | Failed to unlink the template. | ||||||||||
| 937 | |||||||||||
| 938 | =head2 18, notInDir | ||||||||||
| 939 | |||||||||||
| 940 | The requested template is not in this Toader dir. | ||||||||||
| 941 | |||||||||||
| 942 | =head2 19, noToaderObj | ||||||||||
| 943 | |||||||||||
| 944 | No L<Toader> object is given. | ||||||||||
| 945 | |||||||||||
| 946 | =head1 AUTHOR | ||||||||||
| 947 | |||||||||||
| 948 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||
| 949 | |||||||||||
| 950 | =head1 BUGS | ||||||||||
| 951 | |||||||||||
| 952 | Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through | ||||||||||
| 953 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will be notified, and then you'll | ||||||||||
| 954 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 955 | |||||||||||
| 956 | |||||||||||
| 957 | |||||||||||
| 958 | |||||||||||
| 959 | =head1 SUPPORT | ||||||||||
| 960 | |||||||||||
| 961 | You can find documentation for this module with the perldoc command. | ||||||||||
| 962 | |||||||||||
| 963 | perldoc Toader::Templates | ||||||||||
| 964 | |||||||||||
| 965 | |||||||||||
| 966 | You can also look for information at: | ||||||||||
| 967 | |||||||||||
| 968 | =over 4 | ||||||||||
| 969 | |||||||||||
| 970 | =item * RT: CPAN's request tracker | ||||||||||
| 971 | |||||||||||
| 972 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader> | ||||||||||
| 973 | |||||||||||
| 974 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 975 | |||||||||||
| 976 | L<http://annocpan.org/dist/Toader> | ||||||||||
| 977 | |||||||||||
| 978 | =item * CPAN Ratings | ||||||||||
| 979 | |||||||||||
| 980 | L<http://cpanratings.perl.org/d/Toader> | ||||||||||
| 981 | |||||||||||
| 982 | =item * Search CPAN | ||||||||||
| 983 | |||||||||||
| 984 | L<http://search.cpan.org/dist/Toader/> | ||||||||||
| 985 | |||||||||||
| 986 | =back | ||||||||||
| 987 | |||||||||||
| 988 | |||||||||||
| 989 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 990 | |||||||||||
| 991 | |||||||||||
| 992 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 993 | |||||||||||
| 994 | Copyright 2013 Zane C. Bowers-Hadley. | ||||||||||
| 995 | |||||||||||
| 996 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 997 | under the terms of either: the GNU General Public License as published | ||||||||||
| 998 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 999 | |||||||||||
| 1000 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 1001 | |||||||||||
| 1002 | |||||||||||
| 1003 | =cut | ||||||||||
| 1004 | |||||||||||
| 1005 | 5 | 1; # End of Toader::Templates | |||||||||