blib/lib/Seshat.pm

filter: Statementstmt 32.1% 18 / 56 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 27.9% 24 / 86 CC 12 SCAR 42.1
CC
12
Cov
24%
write
110.0
new
12.0
BEGIN
1.0
CRAP 67.1
↑ Summary
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
BranchTrueFalseTotal
if (exists $self->{"PARAM"}{$_}) 0 0 0
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
BranchTrueFalseTotal
open FH, '>>' . $self->{"FILE"} or $@ = 'cant open ' . $self->{"FILE"} . ": $!" && (return undef) 0 0 0
Condition0%0/2
'cant open ' . $self->{'FILE'} . ": $!" && (return undef)
!ll
00
MC/DC0%0/1
'cant open ' . $self->{'FILE'} . ": $!" && (return undef)
'cant open ' . $self->{'FILE'} . ": $!"
Truth table0%0/2
A
A= 'cant open ' . $self->{'FILE'} . ": $!"
Aresult
00
11
48 && return undef);
49 0 my $flocked = 0;
50 0 ▶ while (! $flocked ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flocked) 0 0 0
51 0 ▶ if (! flock(FH, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not flock(FH, 2)) { } 0 0 0
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
BranchTrueFalseTotal
if ($self->{'FLAG'} eq 1) { } 0 0 0
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
BranchTrueFalseTotal
if ($flag eq 1) { } 0 0 0
elsif ($flag eq 0) { } 0 0 0
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
BranchTrueFalseTotal
close FH or $@ = "can't close $!" && (return undef) 0 0 0
Condition0%0/2
"can't close $!" && (return undef)
!ll
00
MC/DC0%0/1
"can't close $!" && (return undef)
"can't close $!"
Truth table0%0/2
A
A= "can't close $!"
Aresult
00
11
82 or ($@= "can't close $!"
83 && return undef);
84 0 return 1;
85 }
86  
87 1 1;
88 __END__
↑ Summary