line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Karmasphere::Publisher; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1657
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
4
|
use Carp qw(cluck); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
4
|
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
10
|
1
|
|
|
1
|
|
4
|
use Time::HiRes; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
12
|
|
11
|
1
|
|
|
1
|
|
16324
|
use File::Temp; |
|
1
|
|
|
|
|
29740
|
|
|
1
|
|
|
|
|
96
|
|
12
|
1
|
|
|
1
|
|
1098
|
use IO::File; |
|
1
|
|
|
|
|
1341
|
|
|
1
|
|
|
|
|
400
|
|
13
|
1
|
|
|
1
|
|
16803
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
73312
|
|
|
1
|
|
|
|
|
36
|
|
14
|
1
|
|
|
1
|
|
2029
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
2590
|
|
|
1
|
|
|
|
|
143
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
BEGIN { |
17
|
1
|
|
|
1
|
|
23
|
@ISA = qw(Exporter); |
18
|
1
|
|
|
|
|
3
|
@EXPORT_OK = qw(); |
19
|
1
|
|
|
|
|
808
|
%EXPORT_TAGS = ( |
20
|
|
|
|
|
|
|
'all' => \@EXPORT_OK, |
21
|
|
|
|
|
|
|
'ALL' => \@EXPORT_OK, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
27
|
0
|
0
|
|
|
|
|
my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; |
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Check for Principal, Credentials |
29
|
0
|
|
|
|
|
|
return bless $self, $class; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _output_file { |
33
|
0
|
|
|
0
|
|
|
my ($input, $output, $index) = @_; |
34
|
0
|
0
|
|
|
|
|
return $output if ref $output; # An IO::File |
35
|
0
|
0
|
|
|
|
|
return new IO::File("> $output") if defined $output; |
36
|
0
|
|
|
|
|
|
my $temp = $input; |
37
|
0
|
|
|
|
|
|
return new File::Temp( |
38
|
|
|
|
|
|
|
TEMPLATE => "$input.$$.$index.XXXXXX", |
39
|
|
|
|
|
|
|
SUFFIX => ".ktmp", |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Do not fuck with this method, Karma-Syndicator calls it. |
44
|
|
|
|
|
|
|
# we output to a temporary file and write to it. |
45
|
|
|
|
|
|
|
# once we're done writing to it, we rename the temp file to the real filename. |
46
|
|
|
|
|
|
|
sub parse { |
47
|
0
|
|
|
0
|
0
|
|
my ($self, $input, $class, $outputs, %args) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
eval qq{ require $class; }; |
50
|
0
|
0
|
|
|
|
|
die $@ if $@; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $fh = new IO::File("< $input"); |
53
|
0
|
|
|
|
|
|
my $parser = $class->new(fh => $fh, %args); |
54
|
0
|
|
|
|
|
|
my $streams = $parser->streams; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
0
|
|
|
|
$outputs ||= []; # An array of filenames. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# print STDERR "outputs are " . Dumper($outputs); |
59
|
0
|
|
|
|
|
|
my @files = map { _output_file($outputs->[$_], undef, $_) } (0..$#$streams); |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# print STDERR ">>> parse temp files are " . Dumper(\@files); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
for my $i (0..$#$streams) { |
63
|
0
|
0
|
|
|
|
|
if (not $outputs->[$i]) { |
64
|
0
|
|
|
|
|
|
cluck ("parser $parser for input $input defines stream $i, but there is no corresponding output filename!"); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# this is a ridiculously slow inner loop. can we optimize? |
69
|
0
|
|
|
|
|
|
while (my @records = $parser->parse) { |
70
|
0
|
|
|
|
|
|
for my $record (@records) { |
71
|
0
|
0
|
|
|
|
|
next if not defined $record; |
72
|
0
|
|
|
|
|
|
my $file = $files[$record->stream]; |
73
|
0
|
|
|
|
|
|
print $file $record->as_string, "\n"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
foreach my $i (0 .. $#$streams) { |
78
|
0
|
|
|
|
|
|
my $fh = $files[$i]; |
79
|
0
|
|
|
|
|
|
print STDERR " >> stream $i: renaming " . $fh->filename() . " to " . $outputs->[$i] . "\n"; |
80
|
0
|
|
|
|
|
|
rename($fh->filename, $outputs->[$i]); |
81
|
0
|
|
|
|
|
|
chmod 0644, $outputs->[$i]; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return 1; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub publish { |
88
|
0
|
|
|
0
|
0
|
|
my ($self, $file, $class, $params) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $url = $params->{url}; |
93
|
0
|
|
|
|
|
|
my $feed = $params->{feed}; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $req = POST ($url, |
96
|
|
|
|
|
|
|
Content_Type => "form-data", |
97
|
|
|
|
|
|
|
Content => |
98
|
|
|
|
|
|
|
[ feed_id => $feed, |
99
|
|
|
|
|
|
|
login => $params->{user}, |
100
|
|
|
|
|
|
|
password => $params->{pass}, |
101
|
|
|
|
|
|
|
data_source => "upload", |
102
|
|
|
|
|
|
|
data_file => [ $file ], |
103
|
|
|
|
|
|
|
]); |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if (defined $params->{htuser}) { |
106
|
0
|
|
|
|
|
|
$req->headers->authorization_basic($params->{htuser}, |
107
|
|
|
|
|
|
|
$params->{htpass}); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $res = $ua->request($req); |
111
|
0
|
|
|
|
|
|
return $res; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |