| 1 | package Seshat; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | require Exporter; | |||||||||||||||||||
| 9 | 1 | require AutoLoader; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | @ISA = qw(Exporter AutoLoader); | |||||||||||||||||||
| 12 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||
| 13 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||
| 14 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||
| 15 | 1 | @EXPORT = qw( | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | 1 | $VERSION = '1.1'; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 21 | 0 | my $classname = shift; | |||||||||||||||||||
| 22 | 0 | my $filename = shift; | |||||||||||||||||||
| 23 | 0 | my %params = @_; | |||||||||||||||||||
| 24 | 0 | my $self = {}; | |||||||||||||||||||
| 25 | 0 | $self->{NAME} = "Seshat"; | |||||||||||||||||||
| 26 | 0 | $self->{FILE} = $filename; | |||||||||||||||||||
| 27 | 0 | $self->{FLAG} = 0; | |||||||||||||||||||
| 28 | 0 | $self->{POS} = 0; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # -> defaults -< # | ||||||||||||||||||||
| 31 | 0 | $self->{PARAM}->{LOG_LEVEL} = "0"; | |||||||||||||||||||
| 32 | 0 | $self->{PARAM}->{DATE_FORMAT} ="%a %b %e %H:%M:%S %Y"; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | foreach (keys %params) { | |||||||||||||||||||
| 36 | 0 | ▶ | if (exists $self->{PARAM}->{$_}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 0 | $self->{PARAM}->{$_} = $params{$_}; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | 0 | bless ($self,$classname); | |||||||||||||||||||
| 41 | 0 | return $self; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | sub write { | ||||||||||||||||||
|
Subroutine
write: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||
| 45 | 0 | my ($self, $string, $flag) = @_; | |||||||||||||||||||
| 46 | open(FH, ">>".$self->{FILE}) | ||||||||||||||||||||
| 47 | 0 | ▶ | or ( $@="cant open ".$self->{FILE}.": $!" | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
'cant open ' . $self->{'FILE'} . ": $!" && (return undef)
MC/DC0%0/1
'cant open ' . $self->{'FILE'} . ": $!" && (return undef)
'cant open ' . $self->{'FILE'} . ": $!"
Truth table0%0/2
A
A= 'cant open ' . $self->{'FILE'} . ": $!"
| |||||||||||||||||||||
| 48 | && return undef); | ||||||||||||||||||||
| 49 | 0 | my $flocked = 0; | |||||||||||||||||||
| 50 | 0 | ▶ | while (! $flocked ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | ▶ | if (! flock(FH, 2)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | sleep 1; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||
| 55 | 0 | $flocked = 1; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | my $print_string; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | ▶ | if ($self->{FLAG} eq 1) { seek(FH,$self->{POS},0) } # the line is not blank | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||
| 63 | #$print_string = strftime "%a %b %e %H:%M:%S %Y", localtime; | ||||||||||||||||||||
| 64 | 0 | $print_string = strftime $self->{PARAM}->{DATE_FORMAT}, localtime; | |||||||||||||||||||
| 65 | 0 | $print_string .= " : $0 : "; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | 0 | $print_string .= "$string"; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | ▶ | if ($flag eq 1) { # new line... | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 70 | 0 | $print_string .= "\n"; | |||||||||||||||||||
| 71 | 0 | print FH $print_string; | |||||||||||||||||||
| 72 | 0 | $self->{FLAG} = 0; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | elsif ($flag eq 0) { #no new line... | ||||||||||||||||||||
| 75 | 0 | print FH $print_string; | |||||||||||||||||||
| 76 | 0 | $self->{FLAG} = 1; | |||||||||||||||||||
| 77 | 0 | my $index = tell(FH); | |||||||||||||||||||
| 78 | 0 | $self->{POS} = $index; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | ▶ | close(FH) | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
"can't close $!" && (return undef)
MC/DC0%0/1
"can't close $!" && (return undef)
"can't close $!"
Truth table0%0/2
A
A= "can't close $!"
| |||||||||||||||||||||
| 82 | or ($@= "can't close $!" | ||||||||||||||||||||
| 83 | && return undef); | ||||||||||||||||||||
| 84 | 0 | return 1; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 1 | 1; | |||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||