line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Kritika; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
394
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use JSON (); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
13
|
|
9
|
1
|
|
|
1
|
|
4
|
use Cwd qw(abs_path); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
10
|
1
|
|
|
1
|
|
541
|
use HTTP::Tiny; |
|
1
|
|
|
|
|
29731
|
|
|
1
|
|
|
|
|
347
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
0
|
3340
|
my $class = shift; |
14
|
2
|
|
|
|
|
7
|
my (%params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
|
|
3
|
my $self = {}; |
17
|
2
|
|
|
|
|
3
|
bless $self, $class; |
18
|
|
|
|
|
|
|
|
19
|
2
|
50
|
|
|
|
8
|
$self->{base_url} = $params{base_url} or die 'base_url required'; |
20
|
2
|
50
|
|
|
|
7
|
$self->{token} = $params{token} or die 'token required'; |
21
|
2
|
|
|
|
|
3
|
$self->{root} = $params{root}; |
22
|
|
|
|
|
|
|
|
23
|
2
|
|
33
|
|
|
11
|
$self->{ua} = $params{ua} || HTTP::Tiny->new; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
5
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub validate { |
29
|
2
|
|
|
2
|
0
|
236
|
my $self = shift; |
30
|
2
|
|
|
|
|
4
|
my ($path) = @_; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
112
|
$path = abs_path($path); |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
2
|
my $content = do { |
35
|
2
|
|
|
|
|
8
|
local $/; |
36
|
2
|
50
|
|
|
|
45
|
open my $fh, '<', $path or die "Can't open file '$path': $!"; |
37
|
2
|
|
|
|
|
30
|
<$fh>; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
3
|
my $ua = $self->{ua}; |
41
|
|
|
|
|
|
|
|
42
|
2
|
50
|
|
|
|
4
|
if (my $root = $self->{root}) { |
43
|
2
|
|
|
|
|
76
|
$root = abs_path($root); |
44
|
2
|
|
|
|
|
40
|
$path =~ s{^$root}{}; |
45
|
2
|
|
|
|
|
5
|
$path =~ s{^/}{}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $response = $ua->post_form( |
49
|
|
|
|
|
|
|
"$self->{base_url}/validate", |
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
content => $content, |
52
|
|
|
|
|
|
|
path => $path |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
{headers => {Authorization => 'Token ' . $self->{token}}} |
55
|
2
|
|
|
|
|
33
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
die |
58
|
|
|
|
|
|
|
"Remote error: $response->{status} $response->{reason}; $response->{content}\n" |
59
|
2
|
50
|
|
|
|
130
|
unless $response->{success}; |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
15
|
return JSON::decode_json($response->{content}); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
__END__ |