| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Convos::Archive::File; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Convos::Archive::File - Archive to file |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
L is a subclass of L which use plain |
|
10
|
|
|
|
|
|
|
files on disk. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
4
|
use Mojo::Base 'Convos::Archive'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
15
|
1
|
|
|
1
|
|
97
|
use File::Path qw( make_path remove_tree ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
41
|
|
|
16
|
1
|
|
|
1
|
|
4
|
use File::Spec::Functions qw( catdir catfile ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
38
|
|
|
17
|
1
|
|
|
1
|
|
4
|
use Time::Piece qw( gmtime ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
9
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 log_dir |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Path to write logs in. |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has log_dir => sub { die "log_dir() need to be defined in constructor"; }; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 flush |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
See L. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub flush { |
|
38
|
0
|
|
|
0
|
1
|
|
my ($self, $conn) = @_; |
|
39
|
0
|
|
|
|
|
|
remove_tree(catdir $self->log_dir, $conn->login, $conn->name); |
|
40
|
0
|
|
|
|
|
|
return $self; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 save |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
See L. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub save { |
|
50
|
0
|
|
|
0
|
1
|
|
my ($self, $conn, $message) = @_; |
|
51
|
0
|
|
|
|
|
|
my $ts = gmtime($message->{timestamp}); |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my @base = ($self->log_dir, $conn->login, $conn->name); |
|
54
|
0
|
0
|
|
|
|
|
push @base, $message->{target} if $message->{target}; |
|
55
|
0
|
|
|
|
|
|
push @base, $ts->strftime('%y'), $ts->strftime('%m'); |
|
56
|
0
|
|
|
|
|
|
my $path = catdir @base; |
|
57
|
0
|
0
|
|
|
|
|
make_path $path unless $self->{paths}{$path}++; |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$path = catfile $path, $ts->strftime('%d.log'); |
|
60
|
0
|
0
|
|
|
|
|
open my $FH, '>>', $path or die "Cannot write to $path: $!"; |
|
61
|
0
|
|
0
|
|
|
|
printf {$FH} "%s :%s!%s@%s %s\n", $ts->hms, map { $_ // '' } @{$message}{qw(nick user host message)}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
close $FH or die "Cannot close $path: $!"; |
|
63
|
0
|
|
|
|
|
|
return $self; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
See L. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AUTHOR |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Jan Henning Thorsen - C |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Marcus Ramberg - C |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |