line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sweat::ArticleHandler; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
23
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
109
|
|
4
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
59
|
|
5
|
3
|
|
|
3
|
|
15
|
use Moo; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
19
|
|
6
|
3
|
|
|
3
|
|
8370
|
use namespace::clean; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
25
|
|
7
|
3
|
|
|
3
|
|
823
|
use utf8::all; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
30
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
4693
|
use Types::Standard qw( Str Maybe Int ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
50
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
2476
|
use Storable qw(freeze thaw); |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
167
|
|
12
|
3
|
|
|
3
|
|
2891
|
use Path::Tiny; |
|
3
|
|
|
|
|
35367
|
|
|
3
|
|
|
|
|
1544
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'tempdir' => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => sub { $_[0]->isa('Path::Tiny') }, |
17
|
|
|
|
|
|
|
default => sub { Path::Tiny->tempdir( CLEANUP => 1 ) }, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'next_filename' => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
isa => Int, |
23
|
|
|
|
|
|
|
default => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'last_article_read' => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
isa => Int, |
29
|
|
|
|
|
|
|
default => 0, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add_article { |
33
|
0
|
|
|
0
|
0
|
|
my ($self, $article) = @_; |
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
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $next_filename = $self->last_article_read + 1; |
46
|
0
|
|
|
|
|
|
my $next_file = path( $self->tempdir, $next_filename ); |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if ( -e $next_file ) { |
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
|
|
|
|
|
|
|
1; |