| 1 | # | ||||||||||||||||||||
| 2 | # @author Bodo (Hugo) Barwich | ||||||||||||||||||||
| 3 | # @version 2026-03-21 | ||||||||||||||||||||
| 4 | # @package File Access Driver | ||||||||||||||||||||
| 5 | # @subpackage lib/File/Access/Driver.pm | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | # This module defines the a class to interact with files | ||||||||||||||||||||
| 8 | # | ||||||||||||||||||||
| 9 | #--------------------------------- | ||||||||||||||||||||
| 10 | # Requirements: | ||||||||||||||||||||
| 11 | # | ||||||||||||||||||||
| 12 | #--------------------------------- | ||||||||||||||||||||
| 13 | # Extensions: | ||||||||||||||||||||
| 14 | # | ||||||||||||||||||||
| 15 | #--------------------------------- | ||||||||||||||||||||
| 16 | # Configurations: | ||||||||||||||||||||
| 17 | # | ||||||||||||||||||||
| 18 | #--------------------------------- | ||||||||||||||||||||
| 19 | # Features: | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | #============================================================================== | ||||||||||||||||||||
| 22 | # The File::Access::Driver Package | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | =head1 NAME | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | File::Access::Driver - Convenient File Access with "Batteries included" | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | package File::Access::Driver; | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | our $VERSION = '1.0.2'; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 35 | #Dependencies | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 1 | ▶ | use Fcntl ':flock'; # import LOCK_* constants | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | 1 | ▶ | use File::Path qw(make_path); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | C<File::Access::Driver> is a class for convenient file access designed to reduce | ||||||||||||||||||||
| 43 | the code needed to interact with files. | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | It has grown to a "I<Batteries included>" solution covering the most file access | ||||||||||||||||||||
| 46 | use cases. | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | It will not produce exceptions but instead report the errors over the C<getErrorCode()> | ||||||||||||||||||||
| 49 | and the C<getErrorString()> methods. | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | =head1 SYNOPSIS | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | The C<File::Access::Driver> can be used as seen in the "I<File Write>" test: | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | use File::Access::Driver; | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | my $driver = File::Access::Driver->new( 'filepath' => $spath . 'files/out/testfile_out.txt' ); | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | # Make sure the file does not exist | ||||||||||||||||||||
| 60 | is( $driver->Delete(), 1, "File Delete: Delete operation 1 correct" ); | ||||||||||||||||||||
| 61 | is( $driver->Exists(), 0, "File Exist: File does not exist anymore" ); | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | $driver->writeContent(q(This is the multi line content for the test file. | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | It will be written into the test file. | ||||||||||||||||||||
| 66 | The file should only contain this text. | ||||||||||||||||||||
| 67 | Also the file should be created. | ||||||||||||||||||||
| 68 | )); | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | printf( | ||||||||||||||||||||
| 71 | "Test File Exists - File '%s': Write finished with [%d]\n", | ||||||||||||||||||||
| 72 | $driver->getFileName(), | ||||||||||||||||||||
| 73 | $driver->getErrorCode() | ||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||
| 75 | printf( | ||||||||||||||||||||
| 76 | "Test File Exists - File '%s': Write Report:\n'%s'\n", | ||||||||||||||||||||
| 77 | $driver->getFileName(), | ||||||||||||||||||||
| 78 | ${ $driver->getReportString() } | ||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||
| 80 | printf( | ||||||||||||||||||||
| 81 | "Test File Exists - File '%s': Write Error:\n'%s'\n", | ||||||||||||||||||||
| 82 | $driver->getFileName(), | ||||||||||||||||||||
| 83 | ${ $driver->getErrorString() } | ||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | is( $driver->getErrorCode(), 0, "Write Error Code: No errors have occurred" ); | ||||||||||||||||||||
| 87 | is( ${ $driver->getErrorString() }, '', "Write Error Message: No errors are reported" ); | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | is( $driver->Exists(), 1, "File Exist: File does exist now" ); | ||||||||||||||||||||
| 90 | isnt( $driver->getFileSize(), 0, "File Size: File is not empty anymore" ); | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 95 | #Constructors | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =head1 METHODS | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =head2 Constructor | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =head3 new ( [ CONFIGURATIONS ] ) | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | This is the constructor for a new C<File::Access::Driver> object. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | B<Parameters:> | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =over 4 | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =item C<CONFIGURATIONS> | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | Key and value pairs containing the configurations. | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | B<Recognized fields:> | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | C<filedirectory> - The directory where the file is located. | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | C<filename> - The base name of the file. | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | C<filepath> - The complete path with directory and file base name. | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =back | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | See L<Method C<setFileDirectory()>|/"setFileDirectory ( DIRECTORY )"> | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | See L<Method C<setFileName()>|/"setFileName ( NAME )"> | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | sub new { | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | #Take the Method Parameters | ||||||||||||||||||||
| 132 | 6 | ▶ | my ( $invocant, %hshprms ) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||
| 133 | 6 | ▶ | my $class = ref($invocant) || $invocant; | ||||||||||||||||||
|
Condition33%1/3
ref $invocant || $invocant
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant
$invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
| |||||||||||||||||||||
| 134 | 6 | my $self = undef; | |||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | # Set the Default Attributes and assign the initial Values | ||||||||||||||||||||
| 137 | 6 | $self = { | |||||||||||||||||||
| 138 | '_file' => undef, | ||||||||||||||||||||
| 139 | '_directory_name' => '', | ||||||||||||||||||||
| 140 | '_file_name' => '', | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | # A Reference to the Content Text | ||||||||||||||||||||
| 143 | '_file_content' => undef, | ||||||||||||||||||||
| 144 | '_file_content_lines' => undef, | ||||||||||||||||||||
| 145 | '_file_time' => -1, | ||||||||||||||||||||
| 146 | '_file_access_time' => -1, | ||||||||||||||||||||
| 147 | '_file_size' => -1, | ||||||||||||||||||||
| 148 | '_package_size' => 32768, | ||||||||||||||||||||
| 149 | '_buffered' => 0, | ||||||||||||||||||||
| 150 | '_persistent' => 0, | ||||||||||||||||||||
| 151 | '_locked' => 0, | ||||||||||||||||||||
| 152 | '_writable' => 0, | ||||||||||||||||||||
| 153 | '_appendable' => 0, | ||||||||||||||||||||
| 154 | '_report' => '', | ||||||||||||||||||||
| 155 | '_error_message' => '', | ||||||||||||||||||||
| 156 | '_error_code' => 0 | ||||||||||||||||||||
| 157 | }; | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 6 | bless $self, $class; | |||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 6 | ▶ | if ( scalar( keys %hshprms ) > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 162 | 5 | ▶ | $self->setFileDirectory( $hshprms{'filedirectory'} ) if ( defined $hshprms{'filedirectory'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 163 | 5 | ▶ | $self->setFileName( $hshprms{'filename'} ) if ( defined $hshprms{'filename'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 164 | 5 | ▶ | $self->setFilePath( $hshprms{'filepath'} ) if ( defined $hshprms{'filepath'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 165 | } #if(scalar(keys %hshprms) > 0) | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | #Give the Object back | ||||||||||||||||||||
| 168 | 6 | return $self; | |||||||||||||||||||
| 169 | } | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | sub DESTROY { | ||||||||||||||||||||
| 172 | 6 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | # Free the System Resources | ||||||||||||||||||||
| 175 | 6 | $self->freeResources; | |||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 179 | #Administration Methods | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | =head3 setFileDirectory ( DIRECTORY ) | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | This method sets the directory where the file is located. | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | B<Parameters:> | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | =over 4 | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | =item C<DIRECTORY> | ||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | The directory where the file is located. | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | If the directory does not end on a slash C< / > it will be appended. | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | =back | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | sub setFileDirectory { | ||||||||||||||||||||
| 200 | 5 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
setFileDirectory: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | 5 | ▶ | if ( scalar(@_) > 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 203 | 5 | $self->{'_directory_name'} = $_[1]; | |||||||||||||||||||
| 204 | } | ||||||||||||||||||||
| 205 | else #No Parameter given | ||||||||||||||||||||
| 206 | { | ||||||||||||||||||||
| 207 | 0 | $self->{'_directory_name'} = ''; | |||||||||||||||||||
| 208 | } | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 5 | ▶ | $self->{'_directory_name'} = '' unless ( defined $self->{'_directory_name'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | 5 | ▶ | if ( $self->{'_directory_name'} ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 213 | 5 | ▶ | $self->{'_directory_name'} .= '/' unless ( $self->{'_directory_name'} =~ qr#/$# ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 214 | } | ||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | #Clear the File Object | ||||||||||||||||||||
| 217 | 5 | $self->Clear; | |||||||||||||||||||
| 218 | } | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | =head3 setFileName ( NAME ) | ||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | This method sets the base name of the file. | ||||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | B<Parameters:> | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | =over 4 | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | =item C<NAME> | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | The base name of the file. | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | This will also close open file handles and free in-memory cache. | ||||||||||||||||||||
| 233 | |||||||||||||||||||||
| 234 | =back | ||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | See L<Method C<Clear()>|/"Clear ()"> | ||||||||||||||||||||
| 237 | |||||||||||||||||||||
| 238 | =cut | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | sub setFileName { | ||||||||||||||||||||
| 241 | 5 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
setFileName: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | 5 | ▶ | if ( scalar(@_) > 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 244 | 5 | $self->{'_file_name'} = $_[1]; | |||||||||||||||||||
| 245 | } | ||||||||||||||||||||
| 246 | else #No Parameter given | ||||||||||||||||||||
| 247 | { | ||||||||||||||||||||
| 248 | 0 | $self->{'_file_name'} = ''; | |||||||||||||||||||
| 249 | } | ||||||||||||||||||||
| 250 | |||||||||||||||||||||
| 251 | 5 | ▶ | $self->{'_file_name'} = '' unless ( defined $self->{'_file_name'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | # Clear the File Object | ||||||||||||||||||||
| 254 | 5 | $self->Clear; | |||||||||||||||||||
| 255 | } | ||||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | =head3 setFilePath ( PATH ) | ||||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | This method sets the complete path of the file. | ||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | B<Parameters:> | ||||||||||||||||||||
| 262 | |||||||||||||||||||||
| 263 | =over 4 | ||||||||||||||||||||
| 264 | |||||||||||||||||||||
| 265 | =item C<PATH> | ||||||||||||||||||||
| 266 | |||||||||||||||||||||
| 267 | The complete path of the file. | ||||||||||||||||||||
| 268 | |||||||||||||||||||||
| 269 | This will split the C<PATH> and call C<setFileDirectory()> with the directory | ||||||||||||||||||||
| 270 | and C<setFileName()> with the file base name. | ||||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | =back | ||||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | See L<Method C<setFileDirectory()>|/"setFileDirectory ( DIRECTORY )"> | ||||||||||||||||||||
| 275 | |||||||||||||||||||||
| 276 | See L<Method C<setFileName()>|/"setFileName ( NAME )"> | ||||||||||||||||||||
| 277 | |||||||||||||||||||||
| 278 | =cut | ||||||||||||||||||||
| 279 | |||||||||||||||||||||
| 280 | sub setFilePath { | ||||||||||||||||||||
| 281 | 4 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
setFilePath: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||
| 282 | 4 | ▶ | my $sdirnm = $_[1] || ''; | ||||||||||||||||||
|
Condition50%1/2
$_[1] || ''
MC/DC0%0/1
$_[1] || ''
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||
| 283 | 4 | my $sflnm = ''; | |||||||||||||||||||
| 284 | |||||||||||||||||||||
| 285 | 4 | ▶ | if ( $sdirnm ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 286 | 4 | ▶ | if ( index( $sdirnm, '/' ) > -1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 287 | 4 | ▶ | if ( $sdirnm =~ qr#(.*/)([^/]+)$# ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 288 | 4 | $sdirnm = $1; | |||||||||||||||||||
| 289 | 4 | $sflnm = $2; | |||||||||||||||||||
| 290 | } | ||||||||||||||||||||
| 291 | } | ||||||||||||||||||||
| 292 | else #The Path does not include a Slash Sign | ||||||||||||||||||||
| 293 | { | ||||||||||||||||||||
| 294 | 0 | $sflnm = $sdirnm; | |||||||||||||||||||
| 295 | 0 | $sdirnm = ''; | |||||||||||||||||||
| 296 | } | ||||||||||||||||||||
| 297 | } | ||||||||||||||||||||
| 298 | |||||||||||||||||||||
| 299 | #Set the Parsed Values | ||||||||||||||||||||
| 300 | 4 | $self->setFileDirectory($sdirnm); | |||||||||||||||||||
| 301 | 4 | $self->setFileName($sflnm); | |||||||||||||||||||
| 302 | } | ||||||||||||||||||||
| 303 | |||||||||||||||||||||
| 304 | sub changeFileName { | ||||||||||||||||||||
| 305 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
changeFileName: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||
| 306 | 0 | my $sdirnm = ''; | |||||||||||||||||||
| 307 | 0 | ▶ | my $sflnm = $_[1] || ''; | ||||||||||||||||||
|
Condition0%0/2
$_[1] || ''
MC/DC0%0/1
$_[1] || ''
$_[1]
Truth table0%0/2
A
A= $_[1]
| |||||||||||||||||||||
| 308 | 0 | my $irs = 0; | |||||||||||||||||||
| 309 | |||||||||||||||||||||
| 310 | 0 | ▶ | if ( $sflnm ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 311 | |||||||||||||||||||||
| 312 | #If File Name contains Directory Information | ||||||||||||||||||||
| 313 | 0 | ▶ | if ( index( $sflnm, '/' ) > -1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 314 | 0 | ▶ | if ( $sflnm =~ qr#(.*/)([^/]+)$# ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 315 | 0 | $sdirnm = $1; | |||||||||||||||||||
| 316 | 0 | $sflnm = $2; | |||||||||||||||||||
| 317 | } | ||||||||||||||||||||
| 318 | } | ||||||||||||||||||||
| 319 | |||||||||||||||||||||
| 320 | #Assume the same Directory | ||||||||||||||||||||
| 321 | 0 | ▶ | $sdirnm = $self->{'_directory_name'} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 322 | if ( $sdirnm eq '' ); | ||||||||||||||||||||
| 323 | |||||||||||||||||||||
| 324 | 0 | ▶ | if ( $self->Exists ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 325 | 0 | $irs = rename $self->{'_directory_name'} . $self->{'_file_name'}, $sdirnm . $sflnm; | |||||||||||||||||||
| 326 | |||||||||||||||||||||
| 327 | 0 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 328 | |||||||||||||||||||||
| 329 | #Update the File Access Object accordingly but keep the Report History | ||||||||||||||||||||
| 330 | |||||||||||||||||||||
| 331 | 0 | $self->{'_directory_name'} = $sdirnm; | |||||||||||||||||||
| 332 | 0 | $self->{'_file_name'} = $sflnm; | |||||||||||||||||||
| 333 | } | ||||||||||||||||||||
| 334 | else #Change File Name failed | ||||||||||||||||||||
| 335 | { | ||||||||||||||||||||
| 336 | 0 | $irs = 0 + $!; | |||||||||||||||||||
| 337 | |||||||||||||||||||||
| 338 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 339 | "File '" | ||||||||||||||||||||
| 340 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 341 | 0 | . $self->{'_file_name'} | |||||||||||||||||||
| 342 | . "': Change File Name failed with [$irs]!" | ||||||||||||||||||||
| 343 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 344 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 345 | |||||||||||||||||||||
| 346 | 0 | $irs = 0; | |||||||||||||||||||
| 347 | } | ||||||||||||||||||||
| 348 | } | ||||||||||||||||||||
| 349 | else #File does not exist | ||||||||||||||||||||
| 350 | { | ||||||||||||||||||||
| 351 | 0 | $self->{'_error_message'} .= "File does not exist!\n"; | |||||||||||||||||||
| 352 | 0 | ▶ | $self->{'_error_code'} = 3 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 353 | } | ||||||||||||||||||||
| 354 | } | ||||||||||||||||||||
| 355 | else #New File Name was not given | ||||||||||||||||||||
| 356 | { | ||||||||||||||||||||
| 357 | 0 | $self->{'_error_message'} .= "New File Name is not set!\n"; | |||||||||||||||||||
| 358 | 0 | ▶ | $self->{'_error_code'} = 3 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 359 | } | ||||||||||||||||||||
| 360 | |||||||||||||||||||||
| 361 | 0 | return $irs; | |||||||||||||||||||
| 362 | } | ||||||||||||||||||||
| 363 | |||||||||||||||||||||
| 364 | sub setContent { | ||||||||||||||||||||
| 365 | 3 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
setContent: called CC=5 SCAR=17.1
Pod
undocumented
| |||||||||||||||||||||
| 366 | |||||||||||||||||||||
| 367 | 3 | $self->{'_file_content'} = undef; | |||||||||||||||||||
| 368 | 3 | $self->{'_file_content_lines'} = undef; | |||||||||||||||||||
| 369 | 3 | ▶ | $self->{'_buffered'} ||= 1; | ||||||||||||||||||
|
Condition100%2/2
$self->{"_buffered"} ||= 1
MC/DC100%1/1
$self->{"_buffered"} ||= 1
$self->{"_buffered"}
Truth table100%2/2
A
A= $self->{"_buffered"}
| |||||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | 3 | ▶ | if ( scalar(@_) > 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 372 | 3 | ▶ | if ( ref( $_[1] ) eq '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 373 | 3 | $self->{'_file_content'} = \$_[1]; | |||||||||||||||||||
| 374 | } | ||||||||||||||||||||
| 375 | else { | ||||||||||||||||||||
| 376 | 0 | $self->{'_file_content'} = $_[1]; | |||||||||||||||||||
| 377 | } | ||||||||||||||||||||
| 378 | } | ||||||||||||||||||||
| 379 | |||||||||||||||||||||
| 380 | 0 | ${ $self->{'_file_content'} } = '' | |||||||||||||||||||
| 381 | 3 | ▶ | unless ( defined $self->{'_file_content'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 382 | |||||||||||||||||||||
| 383 | } | ||||||||||||||||||||
| 384 | |||||||||||||||||||||
| 385 | sub setContentArray { | ||||||||||||||||||||
| 386 | 1 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
setContentArray: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||||||||||||
| 387 | |||||||||||||||||||||
| 388 | 1 | $self->{'_file_content'} = \''; | |||||||||||||||||||
| 389 | 1 | $self->{'_file_content_lines'} = undef; | |||||||||||||||||||
| 390 | 1 | ▶ | $self->{'_buffered'} ||= 1; | ||||||||||||||||||
|
Condition50%1/2
$self->{"_buffered"} ||= 1
MC/DC0%0/1
$self->{"_buffered"} ||= 1
$self->{"_buffered"}
Truth table50%1/2
A
A= $self->{"_buffered"}
| |||||||||||||||||||||
| 391 | |||||||||||||||||||||
| 392 | 1 | ▶ | if ( scalar(@_) > 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 393 | 1 | ▶ | if ( ref( $_[1] ) eq '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 394 | 0 | $self->{'_file_content_lines'} = \$_[1]; | |||||||||||||||||||
| 395 | } | ||||||||||||||||||||
| 396 | else { | ||||||||||||||||||||
| 397 | 1 | $self->{'_file_content_lines'} = $_[1]; | |||||||||||||||||||
| 398 | } | ||||||||||||||||||||
| 399 | } | ||||||||||||||||||||
| 400 | } | ||||||||||||||||||||
| 401 | |||||||||||||||||||||
| 402 | sub setFileTime { | ||||||||||||||||||||
| 403 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
setFileTime: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 404 | 0 | ▶ | my $itmfl = $_[1] || time; | ||||||||||||||||||
|
Condition0%0/3
$_[1] || time
MC/DC0%0/2
$_[1] || time
$_[1]
time
Truth table0%0/3
A || B
A= $_[1]B= time
| |||||||||||||||||||||
| 405 | 0 | my $irs = 0; | |||||||||||||||||||
| 406 | |||||||||||||||||||||
| 407 | 0 | ▶ | if ( $self->Exists ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 408 | 0 | $self->getFileTime; | |||||||||||||||||||
| 409 | |||||||||||||||||||||
| 410 | 0 | $irs = utime $self->{'_file_access_time'}, $itmfl, $self->{'_directory_name'} . $self->{'_file_name'}; | |||||||||||||||||||
| 411 | |||||||||||||||||||||
| 412 | 0 | ▶ | if ( $irs < 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 413 | 0 | $irs = 0 + $!; | |||||||||||||||||||
| 414 | |||||||||||||||||||||
| 415 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 416 | "File '" | ||||||||||||||||||||
| 417 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 418 | 0 | . $self->{'_file_name'} | |||||||||||||||||||
| 419 | . "': Set File Time failed with [$irs]!" | ||||||||||||||||||||
| 420 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 421 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 422 | |||||||||||||||||||||
| 423 | 0 | $irs = 0; | |||||||||||||||||||
| 424 | } | ||||||||||||||||||||
| 425 | } | ||||||||||||||||||||
| 426 | else #File does not exist | ||||||||||||||||||||
| 427 | { | ||||||||||||||||||||
| 428 | 0 | $self->{'_error_message'} .= "File does not exist!\n"; | |||||||||||||||||||
| 429 | 0 | ▶ | $self->{'_error_code'} = 3 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 430 | } | ||||||||||||||||||||
| 431 | |||||||||||||||||||||
| 432 | 0 | return $irs; | |||||||||||||||||||
| 433 | } | ||||||||||||||||||||
| 434 | |||||||||||||||||||||
| 435 | sub setBuffered { | ||||||||||||||||||||
| 436 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
setBuffered: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 437 | |||||||||||||||||||||
| 438 | 0 | ▶ | if ( scalar(@_) > 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 439 | 0 | ▶ | if ( $_[1] =~ qr/^\d+$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 440 | |||||||||||||||||||||
| 441 | # The parameter is an unsigned whole number | ||||||||||||||||||||
| 442 | |||||||||||||||||||||
| 443 | 0 | ▶ | if ( $_[1] != 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 444 | 0 | $self->{'_buffered'} = 1; | |||||||||||||||||||
| 445 | } | ||||||||||||||||||||
| 446 | else { | ||||||||||||||||||||
| 447 | 0 | $self->{'_buffered'} = 0; | |||||||||||||||||||
| 448 | } | ||||||||||||||||||||
| 449 | } | ||||||||||||||||||||
| 450 | else #The Parameter is not a Number | ||||||||||||||||||||
| 451 | { | ||||||||||||||||||||
| 452 | 0 | $self->{'_buffered'} = 0; | |||||||||||||||||||
| 453 | } | ||||||||||||||||||||
| 454 | } | ||||||||||||||||||||
| 455 | else #No Parameter was given | ||||||||||||||||||||
| 456 | { | ||||||||||||||||||||
| 457 | 0 | $self->{'_buffered'} = 1; | |||||||||||||||||||
| 458 | } | ||||||||||||||||||||
| 459 | } | ||||||||||||||||||||
| 460 | |||||||||||||||||||||
| 461 | sub setPersistent { | ||||||||||||||||||||
| 462 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
setPersistent: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 463 | |||||||||||||||||||||
| 464 | 0 | ▶ | if ( scalar(@_) > 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 465 | 0 | ▶ | if ( $_[1] =~ qr/^\d+$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 466 | |||||||||||||||||||||
| 467 | # The parameter is an unsigned whole number | ||||||||||||||||||||
| 468 | |||||||||||||||||||||
| 469 | 0 | ▶ | if ( $_[1] != 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 470 | 0 | $self->{'_persistent'} = 1; | |||||||||||||||||||
| 471 | } | ||||||||||||||||||||
| 472 | else { | ||||||||||||||||||||
| 473 | 0 | $self->{'_persistent'} = 0; | |||||||||||||||||||
| 474 | } | ||||||||||||||||||||
| 475 | } | ||||||||||||||||||||
| 476 | else #The Parameter is not a Number | ||||||||||||||||||||
| 477 | { | ||||||||||||||||||||
| 478 | 0 | $self->{'_persistent'} = 0; | |||||||||||||||||||
| 479 | } | ||||||||||||||||||||
| 480 | } | ||||||||||||||||||||
| 481 | else #No Parameter was given | ||||||||||||||||||||
| 482 | { | ||||||||||||||||||||
| 483 | 0 | $self->{'_persistent'} = 1; | |||||||||||||||||||
| 484 | } | ||||||||||||||||||||
| 485 | } | ||||||||||||||||||||
| 486 | |||||||||||||||||||||
| 487 | =head3 Create () | ||||||||||||||||||||
| 488 | |||||||||||||||||||||
| 489 | This method will create an empty file. | ||||||||||||||||||||
| 490 | |||||||||||||||||||||
| 491 | If the file already exists it will be truncated. | ||||||||||||||||||||
| 492 | |||||||||||||||||||||
| 493 | =cut | ||||||||||||||||||||
| 494 | |||||||||||||||||||||
| 495 | sub Create { | ||||||||||||||||||||
| 496 | 1 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
Create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 497 | |||||||||||||||||||||
| 498 | 1 | return $self->writeContent(''); | |||||||||||||||||||
| 499 | } | ||||||||||||||||||||
| 500 | |||||||||||||||||||||
| 501 | sub _openrFile { | ||||||||||||||||||||
| 502 | 1 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
_openrFile: called CC=9 SCAR=30.0
| |||||||||||||||||||||
| 503 | 1 | my $irs = 0; | |||||||||||||||||||
| 504 | |||||||||||||||||||||
| 505 | 1 | ▶ | if ( $self->_isOpen() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 506 | |||||||||||||||||||||
| 507 | #Reopen the File in shared Reading Mode | ||||||||||||||||||||
| 508 | 0 | ▶ | $self->_closeFile() if ( $self->_isWritable() ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 509 | } #if($self->_isOpen()) | ||||||||||||||||||||
| 510 | |||||||||||||||||||||
| 511 | 1 | ▶ | unless ( $self->_isOpen() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 512 | 1 | ▶ | if ( $self->Exists() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 513 | |||||||||||||||||||||
| 514 | #Open the File | ||||||||||||||||||||
| 515 | 1 | $irs = open $self->{'_file'}, '<', $self->{'_directory_name'} . $self->{'_file_name'}; | |||||||||||||||||||
| 516 | |||||||||||||||||||||
| 517 | 1 | ▶ | if ( defined $irs ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 518 | 1 | $irs = flock( $self->{'_file'}, LOCK_SH ); | |||||||||||||||||||
| 519 | |||||||||||||||||||||
| 520 | 1 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 521 | 1 | $self->{'_locked'} = 1; | |||||||||||||||||||
| 522 | |||||||||||||||||||||
| 523 | 1 | $irs = 1; | |||||||||||||||||||
| 524 | } #if($irs) | ||||||||||||||||||||
| 525 | } | ||||||||||||||||||||
| 526 | else #The File could not be opened | ||||||||||||||||||||
| 527 | { | ||||||||||||||||||||
| 528 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 529 | "File '" | ||||||||||||||||||||
| 530 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 531 | 0 | . $self->{'_file_name'} . "': " | |||||||||||||||||||
| 532 | . "Open Read failed!\n" | ||||||||||||||||||||
| 533 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 534 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 535 | |||||||||||||||||||||
| 536 | 0 | $irs = 0; | |||||||||||||||||||
| 537 | } #unless(defined $irs) | ||||||||||||||||||||
| 538 | } | ||||||||||||||||||||
| 539 | else #The File does not exist | ||||||||||||||||||||
| 540 | { | ||||||||||||||||||||
| 541 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 542 | "File '" | ||||||||||||||||||||
| 543 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 544 | 0 | . $self->{'_file_name'} . "': " | |||||||||||||||||||
| 545 | . "Open Read failed!\n" | ||||||||||||||||||||
| 546 | . "Message: 'File does not exist.'\n"; | ||||||||||||||||||||
| 547 | 0 | ▶ | $self->{'_error_code'} = 3 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 548 | } | ||||||||||||||||||||
| 549 | } | ||||||||||||||||||||
| 550 | else #The File is open and in Reading Mode | ||||||||||||||||||||
| 551 | { | ||||||||||||||||||||
| 552 | 0 | $irs = 1; | |||||||||||||||||||
| 553 | } | ||||||||||||||||||||
| 554 | |||||||||||||||||||||
| 555 | 1 | return $irs; | |||||||||||||||||||
| 556 | } | ||||||||||||||||||||
| 557 | |||||||||||||||||||||
| 558 | sub _openwFile { | ||||||||||||||||||||
| 559 | 4 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
_openwFile: called CC=14 SCAR=33.7
| |||||||||||||||||||||
| 560 | 4 | my $irs = 0; | |||||||||||||||||||
| 561 | |||||||||||||||||||||
| 562 | 4 | ▶ | unless ( $self->_isWritable() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 563 | 4 | ▶ | $self->_closeFile() if ( $self->_isOpen() ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 564 | |||||||||||||||||||||
| 565 | 4 | ▶ | if ( $self->{'_directory_name'} ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 566 | 4 | ▶ | unless ( -d $self->{'_directory_name'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 567 | 1 | my $idircnt = -1; | |||||||||||||||||||
| 568 | |||||||||||||||||||||
| 569 | $self->{"_report"} .= | ||||||||||||||||||||
| 570 | "Directory '" | ||||||||||||||||||||
| 571 | 1 | . $self->{'_directory_name'} . "': " | |||||||||||||||||||
| 572 | . "Directory does not exist. Directory creating ...\n"; | ||||||||||||||||||||
| 573 | |||||||||||||||||||||
| 574 | #Clear any previous Error Messages | ||||||||||||||||||||
| 575 | 1 | $@ = ''; | |||||||||||||||||||
| 576 | |||||||||||||||||||||
| 577 | 1 | eval { | |||||||||||||||||||
| 578 | #Create the Directory | ||||||||||||||||||||
| 579 | 1 | $idircnt = make_path( $self->{'_directory_name'}, { mode => 0775 } ); | |||||||||||||||||||
| 580 | }; | ||||||||||||||||||||
| 581 | |||||||||||||||||||||
| 582 | 1 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 583 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 584 | "Directory '" | ||||||||||||||||||||
| 585 | 0 | . $self->{'_directory_name'} . "': " | |||||||||||||||||||
| 586 | . "Create Directory failed.\n" | ||||||||||||||||||||
| 587 | . "Message (Code '" | ||||||||||||||||||||
| 588 | . ( $! + 0 ) | ||||||||||||||||||||
| 589 | . "'): '$@'\n"; | ||||||||||||||||||||
| 590 | |||||||||||||||||||||
| 591 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 592 | |||||||||||||||||||||
| 593 | 0 | $idircnt = -1; | |||||||||||||||||||
| 594 | } | ||||||||||||||||||||
| 595 | |||||||||||||||||||||
| 596 | 1 | ▶ | $irs = 1 if ( $idircnt != -1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 597 | } | ||||||||||||||||||||
| 598 | else # Directory does exist | ||||||||||||||||||||
| 599 | { | ||||||||||||||||||||
| 600 | 3 | $irs = 1; | |||||||||||||||||||
| 601 | } | ||||||||||||||||||||
| 602 | } | ||||||||||||||||||||
| 603 | else #The File Directory is not set | ||||||||||||||||||||
| 604 | { | ||||||||||||||||||||
| 605 | 0 | $irs = 1; | |||||||||||||||||||
| 606 | } | ||||||||||||||||||||
| 607 | |||||||||||||||||||||
| 608 | 4 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 609 | 4 | ▶ | if ( $self->{'_file_name'} ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 610 | |||||||||||||||||||||
| 611 | #Open the File | ||||||||||||||||||||
| 612 | 4 | $irs = open $self->{'_file'}, ">", $self->{'_directory_name'} . $self->{'_file_name'}; | |||||||||||||||||||
| 613 | |||||||||||||||||||||
| 614 | 4 | ▶ | if ( defined $irs ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 615 | 4 | $self->{'_writable'} = 1; | |||||||||||||||||||
| 616 | |||||||||||||||||||||
| 617 | 4 | $irs = flock( $self->{'_file'}, LOCK_EX ); | |||||||||||||||||||
| 618 | |||||||||||||||||||||
| 619 | 4 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 620 | 4 | $self->{'_locked'} = 1; | |||||||||||||||||||
| 621 | |||||||||||||||||||||
| 622 | 4 | $irs = 1; | |||||||||||||||||||
| 623 | } | ||||||||||||||||||||
| 624 | } | ||||||||||||||||||||
| 625 | else #The File could not be opened | ||||||||||||||||||||
| 626 | { | ||||||||||||||||||||
| 627 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 628 | "File '" | ||||||||||||||||||||
| 629 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 630 | 0 | . $self->{'_file_name'} | |||||||||||||||||||
| 631 | . "': Open Write failed!\n" | ||||||||||||||||||||
| 632 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 633 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 634 | |||||||||||||||||||||
| 635 | 0 | $irs = 0; | |||||||||||||||||||
| 636 | } | ||||||||||||||||||||
| 637 | } | ||||||||||||||||||||
| 638 | else #The File Name isnt set | ||||||||||||||||||||
| 639 | { | ||||||||||||||||||||
| 640 | 0 | $self->{'_error_message'} .= "File Name isn't set!\n"; | |||||||||||||||||||
| 641 | 0 | ▶ | $self->{'_error_code'} = 3 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 642 | |||||||||||||||||||||
| 643 | 0 | $irs = 0; | |||||||||||||||||||
| 644 | } | ||||||||||||||||||||
| 645 | } | ||||||||||||||||||||
| 646 | } | ||||||||||||||||||||
| 647 | else #The File is already open in Appending Mode | ||||||||||||||||||||
| 648 | { | ||||||||||||||||||||
| 649 | 0 | $irs = 1; | |||||||||||||||||||
| 650 | } #unless($self->_isWritable()) | ||||||||||||||||||||
| 651 | |||||||||||||||||||||
| 652 | 4 | return $irs; | |||||||||||||||||||
| 653 | } | ||||||||||||||||||||
| 654 | |||||||||||||||||||||
| 655 | sub _openaFile { | ||||||||||||||||||||
| 656 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
_openaFile: not called CC=15 SCAR=54.8
| |||||||||||||||||||||
| 657 | 0 | my $irs = 0; | |||||||||||||||||||
| 658 | |||||||||||||||||||||
| 659 | 0 | ▶ | unless ( $self->_isAppendable() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 660 | 0 | ▶ | $self->_closeFile() if ( $self->_isOpen() ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 661 | |||||||||||||||||||||
| 662 | 0 | ▶ | if ( $self->{'_directory_name'} ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 663 | 0 | ▶ | unless ( -d $self->{'_directory_name'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 664 | 0 | my $idircnt = -1; | |||||||||||||||||||
| 665 | |||||||||||||||||||||
| 666 | #Clear any previous Error Messages | ||||||||||||||||||||
| 667 | 0 | $@ = ''; | |||||||||||||||||||
| 668 | |||||||||||||||||||||
| 669 | 0 | eval { | |||||||||||||||||||
| 670 | #Create the Directory | ||||||||||||||||||||
| 671 | 0 | $idircnt = make_path( $self->{'_directory_name'}, { mode => 0775 } ); | |||||||||||||||||||
| 672 | }; | ||||||||||||||||||||
| 673 | |||||||||||||||||||||
| 674 | 0 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 675 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 676 | "Directory '" | ||||||||||||||||||||
| 677 | 0 | . $self->{'_directory_name'} . "': " | |||||||||||||||||||
| 678 | . "Create Directory failed.\n" | ||||||||||||||||||||
| 679 | . "Message (Code '" | ||||||||||||||||||||
| 680 | . ( 0 + $! ) | ||||||||||||||||||||
| 681 | . "'): '$@'\n"; | ||||||||||||||||||||
| 682 | |||||||||||||||||||||
| 683 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 684 | |||||||||||||||||||||
| 685 | 0 | $idircnt = -1; | |||||||||||||||||||
| 686 | } | ||||||||||||||||||||
| 687 | |||||||||||||||||||||
| 688 | 0 | ▶ | $irs = 1 if ( $idircnt != -1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 689 | } | ||||||||||||||||||||
| 690 | else # Directory does exist | ||||||||||||||||||||
| 691 | { | ||||||||||||||||||||
| 692 | 0 | $irs = 1; | |||||||||||||||||||
| 693 | } | ||||||||||||||||||||
| 694 | } | ||||||||||||||||||||
| 695 | else #The File Directory is not set | ||||||||||||||||||||
| 696 | { | ||||||||||||||||||||
| 697 | 0 | $irs = 1; | |||||||||||||||||||
| 698 | } | ||||||||||||||||||||
| 699 | |||||||||||||||||||||
| 700 | 0 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 701 | 0 | ▶ | if ( $self->{'_file_name'} ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 702 | |||||||||||||||||||||
| 703 | #Open the File | ||||||||||||||||||||
| 704 | 0 | $irs = open $self->{'_file'}, ">>", $self->{'_directory_name'} . $self->{'_file_name'}; | |||||||||||||||||||
| 705 | |||||||||||||||||||||
| 706 | 0 | ▶ | if ( defined $irs ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 707 | 0 | $self->{'_writable'} = 1; | |||||||||||||||||||
| 708 | 0 | $self->{'_appendable'} = 1; | |||||||||||||||||||
| 709 | |||||||||||||||||||||
| 710 | 0 | $irs = flock( $self->{'_file'}, LOCK_EX ); | |||||||||||||||||||
| 711 | |||||||||||||||||||||
| 712 | 0 | ▶ | $irs = seek( $self->{'_file'}, 0, SEEK_END ) if ($irs); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 713 | |||||||||||||||||||||
| 714 | 0 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 715 | 0 | $self->{'_locked'} = 1; | |||||||||||||||||||
| 716 | |||||||||||||||||||||
| 717 | 0 | $irs = 1; | |||||||||||||||||||
| 718 | } | ||||||||||||||||||||
| 719 | } | ||||||||||||||||||||
| 720 | else #The File could not be opened | ||||||||||||||||||||
| 721 | { | ||||||||||||||||||||
| 722 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 723 | "File '" | ||||||||||||||||||||
| 724 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 725 | 0 | . $self->{'_file_name'} | |||||||||||||||||||
| 726 | . "': Open Append failed!\n" | ||||||||||||||||||||
| 727 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 728 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 729 | |||||||||||||||||||||
| 730 | 0 | $irs = 0; | |||||||||||||||||||
| 731 | } | ||||||||||||||||||||
| 732 | } | ||||||||||||||||||||
| 733 | else #The File Name isnt set | ||||||||||||||||||||
| 734 | { | ||||||||||||||||||||
| 735 | 0 | $self->{'_error_message'} .= "File Name isn't set!\n"; | |||||||||||||||||||
| 736 | 0 | ▶ | $self->{'_error_code'} = 3 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 737 | } | ||||||||||||||||||||
| 738 | } | ||||||||||||||||||||
| 739 | } | ||||||||||||||||||||
| 740 | else #The File is already open in Appending Mode | ||||||||||||||||||||
| 741 | { | ||||||||||||||||||||
| 742 | 0 | $irs = 1; | |||||||||||||||||||
| 743 | } #unless($self->_isAppendable()) | ||||||||||||||||||||
| 744 | |||||||||||||||||||||
| 745 | 0 | return $irs; | |||||||||||||||||||
| 746 | } | ||||||||||||||||||||
| 747 | |||||||||||||||||||||
| 748 | sub Read { | ||||||||||||||||||||
| 749 | 1 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
Read: called CC=14 SCAR=30.2
Pod
undocumented
| |||||||||||||||||||||
| 750 | 1 | my $irs = 0; | |||||||||||||||||||
| 751 | |||||||||||||||||||||
| 752 | 1 | ${ $self->{'_file_content'} } = ''; | |||||||||||||||||||
| 753 | 1 | $self->{'_file_content_lines'} = undef; | |||||||||||||||||||
| 754 | 1 | ▶ | $self->{'_buffered'} = 1 unless ( $self->{'_buffered'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 755 | 1 | $self->{'_file_time'} = -1; | |||||||||||||||||||
| 756 | 1 | $self->{'_file_size'} = -1; | |||||||||||||||||||
| 757 | |||||||||||||||||||||
| 758 | 1 | ▶ | $self->_openrFile() if ( $self->_isWritable() ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 759 | |||||||||||||||||||||
| 760 | 1 | ▶ | $self->_openrFile() unless ( $self->_isOpen() ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 761 | |||||||||||||||||||||
| 762 | 1 | ▶ | if ( $self->_isOpen() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 763 | 1 | my $scntntln = ''; | |||||||||||||||||||
| 764 | 1 | my $irdcnt = -1; | |||||||||||||||||||
| 765 | |||||||||||||||||||||
| 766 | do #while($irdcnt); | ||||||||||||||||||||
| 767 | 1 | ▶ | { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 768 | 2 | $irdcnt = sysread( $self->{'_file'}, $scntntln, $self->{"_package_size"} ); | |||||||||||||||||||
| 769 | |||||||||||||||||||||
| 770 | 2 | ▶ | if ( defined $irdcnt ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 771 | 2 | ▶ | ${ $self->{'_file_content'} } .= $scntntln if ( $irdcnt > 0 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 772 | } | ||||||||||||||||||||
| 773 | else #An Error has ocurred | ||||||||||||||||||||
| 774 | { | ||||||||||||||||||||
| 775 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 776 | "File '" | ||||||||||||||||||||
| 777 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 778 | 0 | . $self->{'_file_name'} | |||||||||||||||||||
| 779 | . "': Read File failed with [" | ||||||||||||||||||||
| 780 | . ( 0 + $! ) . "]!!" | ||||||||||||||||||||
| 781 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 782 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 783 | } | ||||||||||||||||||||
| 784 | } while ($irdcnt); | ||||||||||||||||||||
| 785 | |||||||||||||||||||||
| 786 | 1 | ▶ | $irs = 1 unless ($!); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 787 | |||||||||||||||||||||
| 788 | 1 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 789 | 1 | my @arrflstt = stat( $self->{'_file'} ); | |||||||||||||||||||
| 790 | |||||||||||||||||||||
| 791 | 1 | ▶ | if ( scalar(@arrflstt) > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 792 | 1 | $self->{'_file_time'} = $arrflstt[9]; | |||||||||||||||||||
| 793 | 1 | $self->{'_file_size'} = $arrflstt[7]; | |||||||||||||||||||
| 794 | } | ||||||||||||||||||||
| 795 | else #The File Attributes are empty | ||||||||||||||||||||
| 796 | { | ||||||||||||||||||||
| 797 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 798 | 0 | "File '" . $self->{'_directory_name'} . $self->{'_file_name'} . "': File Attributes failed!\n"; | |||||||||||||||||||
| 799 | } | ||||||||||||||||||||
| 800 | } | ||||||||||||||||||||
| 801 | |||||||||||||||||||||
| 802 | 1 | ▶ | if ( $self->{'_persistent'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 803 | 0 | ▶ | unless ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 804 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 805 | "File '" | ||||||||||||||||||||
| 806 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 807 | 0 | . $self->{'_file_name'} . "': " | |||||||||||||||||||
| 808 | . "File closing because of Reading Error ...\n"; | ||||||||||||||||||||
| 809 | |||||||||||||||||||||
| 810 | #Close the File | ||||||||||||||||||||
| 811 | 0 | $self->_closeFile(); | |||||||||||||||||||
| 812 | } | ||||||||||||||||||||
| 813 | } | ||||||||||||||||||||
| 814 | else #File is not persistent | ||||||||||||||||||||
| 815 | { | ||||||||||||||||||||
| 816 | #Close the File | ||||||||||||||||||||
| 817 | 1 | $self->_closeFile(); | |||||||||||||||||||
| 818 | } | ||||||||||||||||||||
| 819 | } | ||||||||||||||||||||
| 820 | |||||||||||||||||||||
| 821 | 1 | return $irs; | |||||||||||||||||||
| 822 | } | ||||||||||||||||||||
| 823 | |||||||||||||||||||||
| 824 | sub readContent { | ||||||||||||||||||||
| 825 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
readContent: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 826 | |||||||||||||||||||||
| 827 | 0 | $self->Read(); | |||||||||||||||||||
| 828 | |||||||||||||||||||||
| 829 | 0 | return $self->getContent; | |||||||||||||||||||
| 830 | } | ||||||||||||||||||||
| 831 | |||||||||||||||||||||
| 832 | sub readContentArray { | ||||||||||||||||||||
| 833 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
readContentArray: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 834 | |||||||||||||||||||||
| 835 | 0 | File::Access::Driver::Read $self; | |||||||||||||||||||
| 836 | |||||||||||||||||||||
| 837 | 0 | return $self->getContentArray; | |||||||||||||||||||
| 838 | } | ||||||||||||||||||||
| 839 | |||||||||||||||||||||
| 840 | =head3 Truncate () | ||||||||||||||||||||
| 841 | |||||||||||||||||||||
| 842 | This method will empty an existing file. | ||||||||||||||||||||
| 843 | |||||||||||||||||||||
| 844 | If the file does not exist it will be created. | ||||||||||||||||||||
| 845 | |||||||||||||||||||||
| 846 | =cut | ||||||||||||||||||||
| 847 | |||||||||||||||||||||
| 848 | sub Truncate { | ||||||||||||||||||||
| 849 | 1 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
Truncate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 850 | |||||||||||||||||||||
| 851 | 1 | return $self->writeContent(''); | |||||||||||||||||||
| 852 | } | ||||||||||||||||||||
| 853 | |||||||||||||||||||||
| 854 | sub Write { | ||||||||||||||||||||
| 855 | 4 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
Write: called CC=12 SCAR=28.9
Pod
undocumented
| |||||||||||||||||||||
| 856 | 4 | my $irs = 0; | |||||||||||||||||||
| 857 | |||||||||||||||||||||
| 858 | 4 | ▶ | $self->{'_buffered'} = 1 unless ( $self->{'_buffered'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 859 | 4 | $self->{'_file_time'} = -1; | |||||||||||||||||||
| 860 | 4 | $self->{'_file_access_time'} = -1; | |||||||||||||||||||
| 861 | 4 | $self->{'_file_size'} = -1; | |||||||||||||||||||
| 862 | |||||||||||||||||||||
| 863 | 4 | ▶ | unless ( $self->_isWritable() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 864 | 4 | ▶ | $self->_closeFile() if ( $self->_isOpen() ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 865 | |||||||||||||||||||||
| 866 | #Open the File in Write Mode | ||||||||||||||||||||
| 867 | 4 | $self->_openwFile(); | |||||||||||||||||||
| 868 | } | ||||||||||||||||||||
| 869 | |||||||||||||||||||||
| 870 | 4 | ▶ | if ( $self->_isWritable() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 871 | 4 | my $iwrtcnt = -1; | |||||||||||||||||||
| 872 | 4 | my $content = $self->getContent(); | |||||||||||||||||||
| 873 | 4 | my $icntntlen = length( ${$content} ); | |||||||||||||||||||
| 874 | |||||||||||||||||||||
| 875 | 4 | $irs = 0; | |||||||||||||||||||
| 876 | |||||||||||||||||||||
| 877 | # Write the Content Line to the File | ||||||||||||||||||||
| 878 | 4 | $iwrtcnt = syswrite( $self->{'_file'}, ${$content} ); | |||||||||||||||||||
| 879 | |||||||||||||||||||||
| 880 | 4 | ▶ | if ( defined $iwrtcnt ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 881 | 4 | $irs = 1; | |||||||||||||||||||
| 882 | |||||||||||||||||||||
| 883 | 4 | ▶ | if ( $iwrtcnt != $icntntlen ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 884 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 885 | "File '" | ||||||||||||||||||||
| 886 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 887 | 0 | . $self->{'_file_name'} | |||||||||||||||||||
| 888 | . "': '$iwrtcnt' from '$icntntlen' Bytes written.\n"; | ||||||||||||||||||||
| 889 | } | ||||||||||||||||||||
| 890 | } | ||||||||||||||||||||
| 891 | else # An Error has ocurred | ||||||||||||||||||||
| 892 | { | ||||||||||||||||||||
| 893 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 894 | "File '" | ||||||||||||||||||||
| 895 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 896 | 0 | . $self->{'_file_name'} | |||||||||||||||||||
| 897 | . "': File Write failed!\n" | ||||||||||||||||||||
| 898 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 899 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 900 | } | ||||||||||||||||||||
| 901 | |||||||||||||||||||||
| 902 | 4 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 903 | 4 | my @arrflstt = stat( $self->{'_file'} ); | |||||||||||||||||||
| 904 | |||||||||||||||||||||
| 905 | 4 | ▶ | if ( scalar(@arrflstt) > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 906 | 4 | $self->{'_file_time'} = $arrflstt[9]; | |||||||||||||||||||
| 907 | 4 | $self->{'_file_access_time'} = $arrflstt[8]; | |||||||||||||||||||
| 908 | 4 | $self->{'_file_size'} = $arrflstt[7]; | |||||||||||||||||||
| 909 | } | ||||||||||||||||||||
| 910 | else #The File Attributes are empty | ||||||||||||||||||||
| 911 | { | ||||||||||||||||||||
| 912 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 913 | 0 | "File '" . $self->{'_directory_name'} . $self->{'_file_name'} . "': File Attributes failed!\n"; | |||||||||||||||||||
| 914 | } | ||||||||||||||||||||
| 915 | } | ||||||||||||||||||||
| 916 | |||||||||||||||||||||
| 917 | 4 | ▶ | if ( $self->{'_persistent'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 918 | 0 | ▶ | unless ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 919 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 920 | "File '" | ||||||||||||||||||||
| 921 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 922 | 0 | . $self->{'_file_name'} . "': " | |||||||||||||||||||
| 923 | . "File closing because of Writing Error ...\n"; | ||||||||||||||||||||
| 924 | |||||||||||||||||||||
| 925 | #Close the File | ||||||||||||||||||||
| 926 | 0 | $self->_closeFile(); | |||||||||||||||||||
| 927 | } | ||||||||||||||||||||
| 928 | } | ||||||||||||||||||||
| 929 | else #File is not persistent | ||||||||||||||||||||
| 930 | { | ||||||||||||||||||||
| 931 | #Close the File | ||||||||||||||||||||
| 932 | 4 | $self->_closeFile(); | |||||||||||||||||||
| 933 | } | ||||||||||||||||||||
| 934 | } | ||||||||||||||||||||
| 935 | |||||||||||||||||||||
| 936 | 4 | return $irs; | |||||||||||||||||||
| 937 | } | ||||||||||||||||||||
| 938 | |||||||||||||||||||||
| 939 | sub writeContent { | ||||||||||||||||||||
| 940 | 3 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
writeContent: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 941 | |||||||||||||||||||||
| 942 | 3 | $self->setContent( $_[1] ); | |||||||||||||||||||
| 943 | |||||||||||||||||||||
| 944 | 3 | return File::Access::Driver::Write $self; | |||||||||||||||||||
| 945 | } | ||||||||||||||||||||
| 946 | |||||||||||||||||||||
| 947 | sub appendLine { | ||||||||||||||||||||
| 948 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
appendLine: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||
| 949 | 0 | my $rcntntln = undef; | |||||||||||||||||||
| 950 | 0 | my $irs = 0; | |||||||||||||||||||
| 951 | |||||||||||||||||||||
| 952 | 0 | $self->{'_file_time'} = -1; | |||||||||||||||||||
| 953 | 0 | $self->{'_file_size'} = -1; | |||||||||||||||||||
| 954 | |||||||||||||||||||||
| 955 | 0 | ▶ | if ( scalar(@_) > 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 956 | 0 | ▶ | if ( ref( $_[1] ) ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 957 | 0 | $rcntntln = $_[1]; | |||||||||||||||||||
| 958 | } | ||||||||||||||||||||
| 959 | else { | ||||||||||||||||||||
| 960 | 0 | $rcntntln = \$_[1]; | |||||||||||||||||||
| 961 | } | ||||||||||||||||||||
| 962 | |||||||||||||||||||||
| 963 | 0 | ▶ | if ( $$rcntntln ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 964 | 0 | ▶ | if ( $self->{'_buffered'} > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 965 | 0 | ${ $self->{'_file_content'} } .= $$rcntntln; | |||||||||||||||||||
| 966 | } | ||||||||||||||||||||
| 967 | } | ||||||||||||||||||||
| 968 | } | ||||||||||||||||||||
| 969 | |||||||||||||||||||||
| 970 | 0 | ▶ | unless ( $self->_isAppendable() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 971 | 0 | ▶ | $self->_closeFile() if ( $self->_isOpen() ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 972 | |||||||||||||||||||||
| 973 | #Open the File in Appending Mode | ||||||||||||||||||||
| 974 | 0 | $self->_openaFile(); | |||||||||||||||||||
| 975 | } | ||||||||||||||||||||
| 976 | |||||||||||||||||||||
| 977 | 0 | ▶ | if ( $self->_isAppendable() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 978 | 0 | my $iwrtcnt = -1; | |||||||||||||||||||
| 979 | 0 | my $icntntlen = length($$rcntntln); | |||||||||||||||||||
| 980 | |||||||||||||||||||||
| 981 | 0 | $irs = 0; | |||||||||||||||||||
| 982 | |||||||||||||||||||||
| 983 | #Write the Content Line to the File | ||||||||||||||||||||
| 984 | 0 | $iwrtcnt = syswrite( $self->{'_file'}, $$rcntntln ); | |||||||||||||||||||
| 985 | |||||||||||||||||||||
| 986 | 0 | ▶ | if ( defined $iwrtcnt ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 987 | 0 | $irs = 1; | |||||||||||||||||||
| 988 | |||||||||||||||||||||
| 989 | 0 | ▶ | if ( $iwrtcnt != $icntntlen ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 990 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 991 | "File '" | ||||||||||||||||||||
| 992 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 993 | 0 | . $self->{'_file_name'} . "': " | |||||||||||||||||||
| 994 | . "'$iwrtcnt' from '$icntntlen' Bytes written.\n"; | ||||||||||||||||||||
| 995 | } | ||||||||||||||||||||
| 996 | } | ||||||||||||||||||||
| 997 | else #An Error has ocurred | ||||||||||||||||||||
| 998 | { | ||||||||||||||||||||
| 999 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 1000 | "File '" | ||||||||||||||||||||
| 1001 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 1002 | 0 | . $self->{'_file_name'} | |||||||||||||||||||
| 1003 | . "': File Write failed!\n" | ||||||||||||||||||||
| 1004 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 1005 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||
| 1007 | |||||||||||||||||||||
| 1008 | 0 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1009 | 0 | my @arrflstt = stat( $self->{'_file'} ); | |||||||||||||||||||
| 1010 | |||||||||||||||||||||
| 1011 | 0 | ▶ | if ( scalar(@arrflstt) > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1012 | 0 | $self->{'_file_time'} = $arrflstt[9]; | |||||||||||||||||||
| 1013 | 0 | $self->{'_file_size'} = $arrflstt[7]; | |||||||||||||||||||
| 1014 | } | ||||||||||||||||||||
| 1015 | else #The File Attributes are empty | ||||||||||||||||||||
| 1016 | { | ||||||||||||||||||||
| 1017 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 1018 | 0 | "File '" . $self->{'_directory_name'} . $self->{'_file_name'} . "': File Attributes failed!\n"; | |||||||||||||||||||
| 1019 | } | ||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||
| 1021 | |||||||||||||||||||||
| 1022 | 0 | ▶ | if ( $self->{'_persistent'} > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1023 | 0 | ▶ | unless ( $irs > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1024 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 1025 | "File '" | ||||||||||||||||||||
| 1026 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 1027 | 0 | . $self->{'_file_name'} . "': " | |||||||||||||||||||
| 1028 | . "File closing because of Writing Error ...\n"; | ||||||||||||||||||||
| 1029 | |||||||||||||||||||||
| 1030 | #Close the File | ||||||||||||||||||||
| 1031 | 0 | $self->_closeFile(); | |||||||||||||||||||
| 1032 | } | ||||||||||||||||||||
| 1033 | } | ||||||||||||||||||||
| 1034 | else #File is not persistent | ||||||||||||||||||||
| 1035 | { | ||||||||||||||||||||
| 1036 | #Close the File | ||||||||||||||||||||
| 1037 | 0 | $self->_closeFile(); | |||||||||||||||||||
| 1038 | } | ||||||||||||||||||||
| 1039 | } #if($self->_isAppendable()) | ||||||||||||||||||||
| 1040 | |||||||||||||||||||||
| 1041 | 0 | return $irs; | |||||||||||||||||||
| 1042 | } | ||||||||||||||||||||
| 1043 | |||||||||||||||||||||
| 1044 | sub writeLine { | ||||||||||||||||||||
| 1045 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
writeLine: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 1046 | |||||||||||||||||||||
| 1047 | 0 | return $self->appendLine( $_[1] ); | |||||||||||||||||||
| 1048 | } | ||||||||||||||||||||
| 1049 | |||||||||||||||||||||
| 1050 | sub Delete { | ||||||||||||||||||||
| 1051 | 4 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
Delete: called CC=5 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||
| 1052 | 4 | my $irs = 0; | |||||||||||||||||||
| 1053 | |||||||||||||||||||||
| 1054 | #Close the Open File | ||||||||||||||||||||
| 1055 | 4 | ▶ | $self->_closeFile() if ( $self->_isOpen ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1056 | |||||||||||||||||||||
| 1057 | 4 | ▶ | if ( $self->Exists ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1058 | 2 | $irs = unlink $self->{'_directory_name'} . $self->{'_file_name'}; | |||||||||||||||||||
| 1059 | |||||||||||||||||||||
| 1060 | 2 | ▶ | if ( $irs < 1 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1061 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 1062 | "File '" | ||||||||||||||||||||
| 1063 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 1064 | 0 | . $self->{'_file_name'} | |||||||||||||||||||
| 1065 | . "': Delete File failed with [" | ||||||||||||||||||||
| 1066 | . ( 0 + $! ) . "]!" | ||||||||||||||||||||
| 1067 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 1068 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1069 | |||||||||||||||||||||
| 1070 | 0 | $irs = 0; | |||||||||||||||||||
| 1071 | } | ||||||||||||||||||||
| 1072 | } | ||||||||||||||||||||
| 1073 | else #The File does not exist | ||||||||||||||||||||
| 1074 | { | ||||||||||||||||||||
| 1075 | 2 | $irs = 1; | |||||||||||||||||||
| 1076 | } | ||||||||||||||||||||
| 1077 | |||||||||||||||||||||
| 1078 | 4 | return $irs; | |||||||||||||||||||
| 1079 | } | ||||||||||||||||||||
| 1080 | |||||||||||||||||||||
| 1081 | sub _closeFile { | ||||||||||||||||||||
| 1082 | 5 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
_closeFile: called CC=7 SCAR=23.0
| |||||||||||||||||||||
| 1083 | 5 | my $irs = 0; | |||||||||||||||||||
| 1084 | |||||||||||||||||||||
| 1085 | 5 | ▶ | if ( $self->_isOpen() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1086 | 5 | ▶ | if ( $self->{'_locked'} > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1087 | 5 | $irs = flock( $self->{'_file'}, LOCK_UN ); | |||||||||||||||||||
| 1088 | |||||||||||||||||||||
| 1089 | 5 | ▶ | unless ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1090 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 1091 | "File '" | ||||||||||||||||||||
| 1092 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 1093 | 0 | . $self->{'_file_name'} . "': " | |||||||||||||||||||
| 1094 | . "Lock Release failed!\n" | ||||||||||||||||||||
| 1095 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 1096 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1097 | } | ||||||||||||||||||||
| 1098 | else #File Lock was released | ||||||||||||||||||||
| 1099 | { | ||||||||||||||||||||
| 1100 | 5 | $self->{'_locked'} = 0; | |||||||||||||||||||
| 1101 | } | ||||||||||||||||||||
| 1102 | } | ||||||||||||||||||||
| 1103 | |||||||||||||||||||||
| 1104 | 5 | $irs = close $self->{'_file'}; | |||||||||||||||||||
| 1105 | |||||||||||||||||||||
| 1106 | 5 | ▶ | unless ( $irs > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1107 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 1108 | "File '" | ||||||||||||||||||||
| 1109 | . $self->{'_directory_name'} | ||||||||||||||||||||
| 1110 | 0 | . $self->{'_file_name'} . "': " | |||||||||||||||||||
| 1111 | . "Close failed!\n" | ||||||||||||||||||||
| 1112 | . "Message: '$!'\n"; | ||||||||||||||||||||
| 1113 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1114 | } #unless($irs > 0) | ||||||||||||||||||||
| 1115 | |||||||||||||||||||||
| 1116 | 5 | $self->{'_file'} = undef; | |||||||||||||||||||
| 1117 | 5 | $self->{'_writable'} = 0; | |||||||||||||||||||
| 1118 | 5 | $self->{'_appendable'} = 0; | |||||||||||||||||||
| 1119 | |||||||||||||||||||||
| 1120 | #To Refresh on next Request | ||||||||||||||||||||
| 1121 | 5 | $self->{'_file_access_time'} = -1; | |||||||||||||||||||
| 1122 | 5 | $self->{'_file_time'} = -1; | |||||||||||||||||||
| 1123 | 5 | $self->{'_file_size'} = -1; | |||||||||||||||||||
| 1124 | |||||||||||||||||||||
| 1125 | } | ||||||||||||||||||||
| 1126 | else #The File is not open | ||||||||||||||||||||
| 1127 | { | ||||||||||||||||||||
| 1128 | 0 | $irs = 1; | |||||||||||||||||||
| 1129 | } | ||||||||||||||||||||
| 1130 | |||||||||||||||||||||
| 1131 | 5 | return $irs; | |||||||||||||||||||
| 1132 | } | ||||||||||||||||||||
| 1133 | |||||||||||||||||||||
| 1134 | =head3 Clear () | ||||||||||||||||||||
| 1135 | |||||||||||||||||||||
| 1136 | This method closed the file handle and frees the in-memory cache | ||||||||||||||||||||
| 1137 | and resets also the in-memory file attributes. | ||||||||||||||||||||
| 1138 | |||||||||||||||||||||
| 1139 | =cut | ||||||||||||||||||||
| 1140 | |||||||||||||||||||||
| 1141 | sub Clear { | ||||||||||||||||||||
| 1142 | 10 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
Clear: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 1143 | |||||||||||||||||||||
| 1144 | #Close the Open File | ||||||||||||||||||||
| 1145 | 10 | ▶ | $self->_closeFile() if ( $self->_isOpen() ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1146 | |||||||||||||||||||||
| 1147 | #Clear Content | ||||||||||||||||||||
| 1148 | 10 | $self->{'_file_content'} = undef; | |||||||||||||||||||
| 1149 | 10 | $self->{'_file_content_lines'} = undef; | |||||||||||||||||||
| 1150 | |||||||||||||||||||||
| 1151 | 10 | $self->clearErrors; | |||||||||||||||||||
| 1152 | |||||||||||||||||||||
| 1153 | #To Refresh on next Request | ||||||||||||||||||||
| 1154 | 10 | $self->{'_file_access_time'} = -1; | |||||||||||||||||||
| 1155 | 10 | $self->{'_file_time'} = -1; | |||||||||||||||||||
| 1156 | 10 | $self->{'_file_size'} = -1; | |||||||||||||||||||
| 1157 | |||||||||||||||||||||
| 1158 | } | ||||||||||||||||||||
| 1159 | |||||||||||||||||||||
| 1160 | =head3 clearErrors () | ||||||||||||||||||||
| 1161 | |||||||||||||||||||||
| 1162 | Clear the error and activity report and reset the error code. | ||||||||||||||||||||
| 1163 | |||||||||||||||||||||
| 1164 | =cut | ||||||||||||||||||||
| 1165 | |||||||||||||||||||||
| 1166 | sub clearErrors { | ||||||||||||||||||||
| 1167 | 11 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
clearErrors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 1168 | |||||||||||||||||||||
| 1169 | 11 | $self->{"_report"} = ''; | |||||||||||||||||||
| 1170 | 11 | $self->{'_error_message'} = ''; | |||||||||||||||||||
| 1171 | 11 | $self->{'_error_code'} = 0; | |||||||||||||||||||
| 1172 | } | ||||||||||||||||||||
| 1173 | |||||||||||||||||||||
| 1174 | =head3 freeResources () | ||||||||||||||||||||
| 1175 | |||||||||||||||||||||
| 1176 | This method closed the file handle and frees the in-memory cache. | ||||||||||||||||||||
| 1177 | |||||||||||||||||||||
| 1178 | =cut | ||||||||||||||||||||
| 1179 | |||||||||||||||||||||
| 1180 | sub freeResources { | ||||||||||||||||||||
| 1181 | 6 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
freeResources: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||
| 1182 | |||||||||||||||||||||
| 1183 | 6 | ▶ | if ( $self->_isOpen ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1184 | |||||||||||||||||||||
| 1185 | # Close the Open File | ||||||||||||||||||||
| 1186 | 0 | $self->_closeFile(); | |||||||||||||||||||
| 1187 | } | ||||||||||||||||||||
| 1188 | |||||||||||||||||||||
| 1189 | #Clear Content | ||||||||||||||||||||
| 1190 | 6 | $self->{'_file_content'} = undef; | |||||||||||||||||||
| 1191 | 6 | $self->{'_file_content_lines'} = undef; | |||||||||||||||||||
| 1192 | } | ||||||||||||||||||||
| 1193 | |||||||||||||||||||||
| 1194 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 1195 | #Consultation Methods | ||||||||||||||||||||
| 1196 | |||||||||||||||||||||
| 1197 | sub getFileDirectory { | ||||||||||||||||||||
| 1198 | 3 | ▶ | return $_[0]->{'_directory_name'}; | ||||||||||||||||||
|
Subroutine
getFileDirectory: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||
| 1200 | |||||||||||||||||||||
| 1201 | sub getFileName { | ||||||||||||||||||||
| 1202 | 14 | ▶ | return $_[0]->{'_file_name'}; | ||||||||||||||||||
|
Subroutine
getFileName: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 1203 | } | ||||||||||||||||||||
| 1204 | |||||||||||||||||||||
| 1205 | sub getFilePath { | ||||||||||||||||||||
| 1206 | 3 | ▶ | return $_[0]->{'_directory_name'} . $_[0]->{'_file_name'}; | ||||||||||||||||||
|
Subroutine
getFilePath: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 1207 | } | ||||||||||||||||||||
| 1208 | |||||||||||||||||||||
| 1209 | sub getContent { | ||||||||||||||||||||
| 1210 | 5 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
getContent: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 1211 | |||||||||||||||||||||
| 1212 | $self->{'_file_content'} = \'' | ||||||||||||||||||||
| 1213 | 5 | ▶ | unless ( defined $self->{'_file_content'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1214 | |||||||||||||||||||||
| 1215 | 5 | ▶ | if ( ${ $self->{'_file_content'} } eq '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1216 | 3 | ▶ | if ( scalar( @{ $self->{'_file_content_lines'} } ) > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1217 | 1 | my $content = join( "\n", @{ $self->{'_file_content_lines'} } ); | |||||||||||||||||||
| 1218 | |||||||||||||||||||||
| 1219 | 1 | $self->{'_file_content'} = \$content; | |||||||||||||||||||
| 1220 | } | ||||||||||||||||||||
| 1221 | } | ||||||||||||||||||||
| 1222 | |||||||||||||||||||||
| 1223 | 5 | return $self->{'_file_content'}; | |||||||||||||||||||
| 1224 | } | ||||||||||||||||||||
| 1225 | |||||||||||||||||||||
| 1226 | sub getContentArray { | ||||||||||||||||||||
| 1227 | 1 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
getContentArray: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||
| 1228 | |||||||||||||||||||||
| 1229 | 1 | @{ $self->{'_file_content_lines'} } = () | |||||||||||||||||||
| 1230 | 1 | ▶ | unless ( defined $self->{'_file_content_lines'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1231 | |||||||||||||||||||||
| 1232 | 1 | ▶ | if ( scalar( @{ $self->{'_file_content_lines'} } ) == 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1233 | 1 | ▶ | if ( ${ $self->{'_file_content'} } ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1234 | 1 | @{ $self->{'_file_content_lines'} } = split( "\n", ${ $self->{'_file_content'} } ); | |||||||||||||||||||
| 1235 | } | ||||||||||||||||||||
| 1236 | } | ||||||||||||||||||||
| 1237 | |||||||||||||||||||||
| 1238 | 1 | return $self->{'_file_content_lines'}; | |||||||||||||||||||
| 1239 | } | ||||||||||||||||||||
| 1240 | |||||||||||||||||||||
| 1241 | sub getFileTime { | ||||||||||||||||||||
| 1242 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
getFileTime: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 1243 | |||||||||||||||||||||
| 1244 | 0 | ▶ | if ( $self->Exists() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1245 | 0 | ▶ | if ( $self->{'_file_time'} < 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1246 | 0 | my @arrflstt = stat( $self->{'_directory_name'} . $self->{'_file_name'} ); | |||||||||||||||||||
| 1247 | |||||||||||||||||||||
| 1248 | 0 | $self->{'_file_time'} = -1; | |||||||||||||||||||
| 1249 | 0 | $self->{'_file_access_time'} = -1; | |||||||||||||||||||
| 1250 | 0 | $self->{'_file_size'} = -1; | |||||||||||||||||||
| 1251 | |||||||||||||||||||||
| 1252 | 0 | ▶ | if ( scalar(@arrflstt) > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1253 | 0 | $self->{'_file_time'} = $arrflstt[9]; | |||||||||||||||||||
| 1254 | 0 | $self->{'_file_access_time'} = $arrflstt[8]; | |||||||||||||||||||
| 1255 | 0 | $self->{'_file_size'} = $arrflstt[7]; | |||||||||||||||||||
| 1256 | } | ||||||||||||||||||||
| 1257 | else #The File Attributes are empty | ||||||||||||||||||||
| 1258 | { | ||||||||||||||||||||
| 1259 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 1260 | 0 | "File '" . $self->{'_directory_name'} . $self->{'_file_name'} . "': File Attributes failed!\n"; | |||||||||||||||||||
| 1261 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1262 | } | ||||||||||||||||||||
| 1263 | } | ||||||||||||||||||||
| 1264 | } | ||||||||||||||||||||
| 1265 | else #The File does not exist | ||||||||||||||||||||
| 1266 | { | ||||||||||||||||||||
| 1267 | 0 | $self->{'_file_time'} = -1; | |||||||||||||||||||
| 1268 | 0 | $self->{'_file_access_time'} = -1; | |||||||||||||||||||
| 1269 | 0 | $self->{'_file_size'} = -1; | |||||||||||||||||||
| 1270 | } | ||||||||||||||||||||
| 1271 | |||||||||||||||||||||
| 1272 | 0 | return $self->{'_file_time'}; | |||||||||||||||||||
| 1273 | } | ||||||||||||||||||||
| 1274 | |||||||||||||||||||||
| 1275 | sub getFileSize { | ||||||||||||||||||||
| 1276 | 5 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
getFileSize: called CC=5 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||
| 1277 | |||||||||||||||||||||
| 1278 | 5 | ▶ | if ( $self->Exists() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1279 | 5 | ▶ | if ( $self->{'_file_size'} < 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1280 | 5 | my @arrflstt = stat( $self->{'_directory_name'} . $self->{'_file_name'} ); | |||||||||||||||||||
| 1281 | |||||||||||||||||||||
| 1282 | 5 | $self->{'_file_time'} = -1; | |||||||||||||||||||
| 1283 | 5 | $self->{'_file_access_time'} = -1; | |||||||||||||||||||
| 1284 | 5 | $self->{'_file_size'} = -1; | |||||||||||||||||||
| 1285 | |||||||||||||||||||||
| 1286 | 5 | ▶ | if ( scalar(@arrflstt) > 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1287 | 5 | $self->{'_file_time'} = $arrflstt[9]; | |||||||||||||||||||
| 1288 | 5 | $self->{'_file_access_time'} = $arrflstt[8]; | |||||||||||||||||||
| 1289 | 5 | $self->{'_file_size'} = $arrflstt[7]; | |||||||||||||||||||
| 1290 | } | ||||||||||||||||||||
| 1291 | else #The File Attributes are empty | ||||||||||||||||||||
| 1292 | { | ||||||||||||||||||||
| 1293 | $self->{'_error_message'} .= | ||||||||||||||||||||
| 1294 | 0 | "File '" . $self->{'_directory_name'} . $self->{'_file_name'} . "': File Attributes failed!\n"; | |||||||||||||||||||
| 1295 | 0 | ▶ | $self->{'_error_code'} = 1 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1296 | } | ||||||||||||||||||||
| 1297 | } | ||||||||||||||||||||
| 1298 | } | ||||||||||||||||||||
| 1299 | else #The File does not exist | ||||||||||||||||||||
| 1300 | { | ||||||||||||||||||||
| 1301 | 0 | $self->{'_file_time'} = -1; | |||||||||||||||||||
| 1302 | 0 | $self->{'_file_access_time'} = -1; | |||||||||||||||||||
| 1303 | 0 | $self->{'_file_size'} = -1; | |||||||||||||||||||
| 1304 | } | ||||||||||||||||||||
| 1305 | |||||||||||||||||||||
| 1306 | 5 | return $self->{'_file_size'}; | |||||||||||||||||||
| 1307 | } | ||||||||||||||||||||
| 1308 | |||||||||||||||||||||
| 1309 | sub Exists { | ||||||||||||||||||||
| 1310 | 17 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
Exists: called CC=8 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||
| 1311 | 17 | my $irs = 0; | |||||||||||||||||||
| 1312 | |||||||||||||||||||||
| 1313 | 17 | ▶ | unless ( $self->_isOpen() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1314 | 17 | ▶ | if ( $self->{'_file_name'} ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1315 | 17 | ▶ | if ( $self->{'_directory_name'} ne '' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1316 | 17 | ▶ | $irs = 1 if ( -d $self->{'_directory_name'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1317 | } | ||||||||||||||||||||
| 1318 | else #The Directory Name isnt set | ||||||||||||||||||||
| 1319 | { | ||||||||||||||||||||
| 1320 | 0 | $irs = 1; | |||||||||||||||||||
| 1321 | } | ||||||||||||||||||||
| 1322 | |||||||||||||||||||||
| 1323 | 17 | ▶ | if ($irs) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1324 | 15 | ▶ | $irs = 0 unless ( -e $self->{'_directory_name'} . $self->{'_file_name'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1325 | } | ||||||||||||||||||||
| 1326 | } | ||||||||||||||||||||
| 1327 | else #The File Name isnt set | ||||||||||||||||||||
| 1328 | { | ||||||||||||||||||||
| 1329 | 0 | $self->{'_error_message'} .= "File Name isn't set!\n"; | |||||||||||||||||||
| 1330 | 0 | ▶ | $self->{'_error_code'} = 3 if ( $self->{'_error_code'} < 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1331 | } | ||||||||||||||||||||
| 1332 | } | ||||||||||||||||||||
| 1333 | else #The File is already open | ||||||||||||||||||||
| 1334 | { | ||||||||||||||||||||
| 1335 | 0 | $irs = 1; | |||||||||||||||||||
| 1336 | } | ||||||||||||||||||||
| 1337 | |||||||||||||||||||||
| 1338 | 17 | return $irs; | |||||||||||||||||||
| 1339 | } | ||||||||||||||||||||
| 1340 | |||||||||||||||||||||
| 1341 | sub _isOpen { | ||||||||||||||||||||
| 1342 | 67 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
_isOpen: called CC=4 SCAR=14.0
| |||||||||||||||||||||
| 1343 | 67 | my $iopn = 0; | |||||||||||||||||||
| 1344 | |||||||||||||||||||||
| 1345 | 67 | ▶ | if ( defined $self->{'_file'} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1346 | 10 | ▶ | $iopn = 1 if ( fileno( $self->{'_file'} ) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1347 | } | ||||||||||||||||||||
| 1348 | else #The File Handle is not set | ||||||||||||||||||||
| 1349 | { | ||||||||||||||||||||
| 1350 | 57 | ▶ | $self->{'_file'} = undef unless ( exists $self->{'_file'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1351 | } | ||||||||||||||||||||
| 1352 | |||||||||||||||||||||
| 1353 | 67 | return $iopn; | |||||||||||||||||||
| 1354 | } | ||||||||||||||||||||
| 1355 | |||||||||||||||||||||
| 1356 | sub _isWritable { | ||||||||||||||||||||
| 1357 | 13 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
_isWritable: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 1358 | 13 | my $iopn = 0; | |||||||||||||||||||
| 1359 | |||||||||||||||||||||
| 1360 | 13 | ▶ | if ( $self->_isOpen() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1361 | 4 | ▶ | $iopn = $self->{'_writable'} if ( defined $self->{'_writable'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1362 | } | ||||||||||||||||||||
| 1363 | |||||||||||||||||||||
| 1364 | 13 | return $iopn; | |||||||||||||||||||
| 1365 | } | ||||||||||||||||||||
| 1366 | |||||||||||||||||||||
| 1367 | sub _isAppendable { | ||||||||||||||||||||
| 1368 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||
|
Subroutine
_isAppendable: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 1369 | 0 | my $iopn = 0; | |||||||||||||||||||
| 1370 | |||||||||||||||||||||
| 1371 | 0 | ▶ | if ( $self->_isOpen() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1372 | 0 | ▶ | $iopn = $self->{'_appendable'} if ( defined $self->{'_appendable'} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 1373 | } | ||||||||||||||||||||
| 1374 | |||||||||||||||||||||
| 1375 | 0 | return $iopn; | |||||||||||||||||||
| 1376 | } | ||||||||||||||||||||
| 1377 | |||||||||||||||||||||
| 1378 | sub isBuffered { | ||||||||||||||||||||
| 1379 | 0 | ▶ | return $_[0]->{'_buffered'}; | ||||||||||||||||||
|
Subroutine
isBuffered: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 1380 | } | ||||||||||||||||||||
| 1381 | |||||||||||||||||||||
| 1382 | sub isPersistent { | ||||||||||||||||||||
| 1383 | 0 | ▶ | return $_[0]->{'_persistent'}; | ||||||||||||||||||
|
Subroutine
isPersistent: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 1384 | } | ||||||||||||||||||||
| 1385 | |||||||||||||||||||||
| 1386 | sub getReportString { | ||||||||||||||||||||
| 1387 | 3 | ▶ | return \$_[0]->{"_report"}; | ||||||||||||||||||
|
Subroutine
getReportString: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 1388 | } | ||||||||||||||||||||
| 1389 | |||||||||||||||||||||
| 1390 | sub getErrorString { | ||||||||||||||||||||
| 1391 | 6 | ▶ | return \$_[0]->{'_error_message'}; | ||||||||||||||||||
|
Subroutine
getErrorString: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 1392 | } | ||||||||||||||||||||
| 1393 | |||||||||||||||||||||
| 1394 | sub getErrorCode { | ||||||||||||||||||||
| 1395 | 6 | ▶ | return $_[0]->{'_error_code'}; | ||||||||||||||||||
|
Subroutine
getErrorCode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 1396 | } | ||||||||||||||||||||
| 1397 | |||||||||||||||||||||
| 1398 | 1 | return 1; | |||||||||||||||||||