blib/lib/Sweat/ArticleHandler.pm

filter: Statementstmt 73.1% 30 / 41 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 2 totaltotal 70.1% 40 / 57 CC 2 SCAR 6.1
CC
2
Cov
70%
next_article
6.0
add_article
2.0
BEGIN
1.0
CRAP 1.8
« blib/lib/Sweat/Group.pm ↑ Summary Build »
1 package Sweat::ArticleHandler;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use utf8::all;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Types::Standard qw( Str Maybe Int );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use Storable qw(freeze thaw);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 has 'tempdir' => (
15 is => 'ro',
16 2 ▶ isa => sub { $_[0]->isa('Path::Tiny') },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 2 ▶ default => sub { Path::Tiny->tempdir( CLEANUP => 1 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 3 );
19  
20 3 has 'next_filename' => (
21 is => 'rw',
22 isa => Int,
23 default => 1,
24 );
25  
26 3 has 'last_article_read' => (
27 is => 'rw',
28 isa => Int,
29 default => 0,
30 );
31  
32 sub add_article {
33 0 ▶ my ($self, $article) = @_;
Subroutine add_article: not called CC=1 SCAR=6.9
Pod undocumented
34 0 my $file = path( $self->tempdir, $self->next_filename );
35 0 $self->next_filename( $self->next_filename + 1 );
36  
37 0 $file->spew( freeze( $article ) );
38  
39 # warn "Writing about " . $article->title . " to $file.\n";
40 }
41  
42 sub next_article {
43 0 ▶ my $self = shift;
Subroutine next_article: not called CC=2 SCAR=17.9
Pod undocumented
44  
45 0 my $next_filename = $self->last_article_read + 1;
46 0 my $next_file = path( $self->tempdir, $next_filename );
47  
48 0 ▶ if ( -e $next_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $next_file) { } 0 0 0
49 # warn "Loading from $next_file\n";
50 0 $self->last_article_read( $self->last_article_read + 1 );
51 0 return thaw( $next_file->slurp );
52 }
53 else {
54 # warn "No file at $next_file, chief.\n";
55 0 return undef;
56 }
57 }
58  
59 3 1;
« blib/lib/Sweat/Group.pm ↑ Summary Build »