Chunk/Store/File.pm

filter: Statementstmt 87.5% 35 / 40 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 1 / 1 totaltotal 83.3% 45 / 54 CC 3 SCAR 4.8
CC
3
Cov
84%
store
3.1
__ANON__
1.3
__ANON__
1.1
CRAP 1.6
« Chunk.pm ↑ Summary Chunk/Store.pm »
1 package Log::Log4perl::Appender::Chunk::Store::File;
2 2 $Log::Log4perl::Appender::Chunk::Store::File::VERSION = '0.013';
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 extends qw/Log::Log4perl::Appender::Chunk::Store/;
5  
6 2 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 my $LOGGER = Log::Log4perl->get_logger();
12  
13 0 ▶has 'base_directory' => ( is => 'ro' , isa => 'Str' , default => sub { File::Temp::tempdir() });
Subroutine __ANON__: not called CC=1 SCAR=1.2
14 0 ▶has 'log_folder' => ( is => 'ro' , isa => 'Str' , default => sub{ {'Log4perl_Appender_Chunk_Store_File'}; });
Subroutine __ANON__: not called CC=1 SCAR=2.6
15  
16 2 has '_logging_folder' => ( is => 'ro' , lazy_build => 1 );
17  
18 1 ▶sub _build__logging_folder {
Subroutine _build__logging_folder: called CC=1 SCAR=0.0
19 1 my ($self)= @_;
20 1 return File::Spec->catfile($self->base_directory, $self->log_folder)
21 }
22  
23 1 ▶sub store{
Subroutine store: called CC=3 SCAR=11.4
Pod documented
24 1 my ($self, $chunk_id, $big_message) = @_;
25 1 my $logging_dir = $self->_logging_folder();
26 1 ▶ unless ( -d $logging_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $logging_dir) 1 0 1
27 1 eval { File::Path::mkpath($logging_dir) };
28 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
29 0 $LOGGER->trace("Couldn't create $logging_dir: $@");
30 0 return;
31 }
32 }
33 1 my $chunk_log_file = File::Spec->catfile($logging_dir, $chunk_id);
34 1 $LOGGER->info("Stored log chunk in $chunk_log_file");
35  
36 1 File::Slurp::write_file(
37 $chunk_log_file,
38 {binmode => ':utf8'},
39 $big_message
40 );
41 1 return 1;
42 }
43  
44 2 __PACKAGE__->meta->make_immutable();
45 2 1;
46 __END__
« Chunk.pm ↑ Summary Chunk/Store.pm »