lib/WWW/Hashbang/Pastebin.pm

filter: Statementstmt 98.6% 75 / 76 Branchbran 91.6% 11 / 12 Conditioncond 55.5% 5 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 90.5% 105 / 116 CC 9 SCAR 11.0
CC
9
Cov
94%
__ANON__
6.0
__ANON__
4.0
__ANON__
1.0
CRAP 3.0
↑ Summary script/app.pl »
1 package WWW::Hashbang::Pastebin;
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use 5.014000;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Dancer ':syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Dancer::Plugin::DBIC qw(schema);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Dancer::Plugin::EscapeHTML qw(escape_html);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Integer::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: command line pastebin
13 10 our $VERSION = '0.004'; # VERSION
14  
15  
16 10 my $mapper = do {
17 10 ▶ my $key = config->{key} || join '', ('a'..'z', 0..9);
Condition33%1/3
config()->{'key'} || join('', (('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'), 0..9))
l!l&&r!l&&!r
0100
MC/DC0%0/2
config()->{'key'} || join('', (('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'), 0..9))
config()->{'key'} join('', (('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'), 0..9))
Truth table33%1/3
A || B
A= config()->{'key'}B= join('', (('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'), 0..9))
ABresult
1X1
011
000
18 10 $key =~ tr/+//d;
19 10 Integer::Tiny->new($key);
20 };
21  
22  
23 2 ▶get '/' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
24 2 return template 'index';
25 10 };
26  
27 2 ▶post '/' => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
28 2 ▶ my $paste_content = param('p') || param('sprunge');
Condition66%2/3
param('p') || param('sprunge')
l!l&&r!l&&!r
101
MC/DC50%1/2
param('p') || param('sprunge')
param('p') param('sprunge')
Truth table66%2/3
A || B
A= param('p')B= param('sprunge')
ABresult
1X1
011
000
29 2 my $lang = param('lang');
30  
31 2 ▶ unless ($paste_content) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($paste_content) 1 1 2
32 1 status 'bad_request';
33 1 return 'No paste content received';
34 }
35  
36 1 my $now = DateTime->now( time_zone => 'UTC' );
37 1 my $row = schema->resultset('Paste')->create({
38 paste_content => $paste_content,
39 paste_date => $now,
40 });
41  
42 1 my $ext_id = $mapper->encrypt($row->id);
43 1 my $ext_url = uri_for("/$ext_id");
44 1 ▶ $ext_url = "$ext_url?$lang" if $lang;
Branch: 1 branch
BranchTrueFalseTotal
if $lang 0 1 1
45 1 debug "Created paste $ext_id: $ext_url";
46 1 headers
47 'X-Pastebin-ID' => $ext_id,
48 'X-Pastebin-URL' => $ext_url;
49 1 return "$ext_url\n";
50 10 };
51  
52 31 ▶get '/:id' => sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
53 31 my $ext_id = param('id');
54 31 my $line_nos = ($ext_id =~ s{\+$}{});
55  
56 31 ▶ my $int_id = try { $mapper->decrypt( $ext_id ) } || do {
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%2/3
&try(sub { $mapper->decrypt($ext_id); } ) || do { status('bad_request'); return "'${ext_id}' is not a valid paste ID" }
l!l&&r!l&&!r
2704
MC/DC0%0/2
&try(sub { $mapper->decrypt($ext_id); } ) || do { status('bad_request'); return "'${ext_id}' is not a valid paste ID" }
&try(sub { $mapper->decrypt($ext_id); } ) do { status('bad_request'); return "'${ext_id}' is not a valid paste ID" }
Truth table33%1/3
A || B
A= &try(sub { $mapper->decrypt($ext_id); } )B= do { status('bad_request'); return "'${ext_id}' is not a valid paste ID" }
ABresult
1X1
011
000
57 4 status 'bad_request';
58 4 return "'$ext_id' is not a valid paste ID";
59 };
60 27 debug "paste ID requested: $int_id";
61  
62 27 my $paste = schema->resultset('Paste')->find( $int_id );
63  
64 27 ▶ unless ($paste) {
Branch: 2 branches
BranchTrueFalseTotal
if ($paste) { } 25 2 27
if (do { $paste->deleted }) 2 23 25
65 2 my $msg = "No such paste as '$ext_id'";
66 2 warning $msg;
67 2 content_type('text/plain');
68 2 status 'not_found';
69 2 return $msg;
70 }
71 0 elsif ($paste->deleted) {
72 2 warning "Request was for deleted paste '$ext_id'->'$int_id'";
73 2 status 'gone';
74 2 return "No such paste as '$ext_id'";
75 }
76  
77 23 headers 'X-Pastebin-ID' => $ext_id;
78 23 ▶ if ($line_nos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_nos) { } 13 10 23
79 13 open my $in, '<', \$paste->content;
80 13 ▶ 1 while (<$in>);
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $in) and do { '???' } 20 13 33
81 13 my $lines = $.;
82 13 close $in;
83 13 return template paste => { content => $paste->content, lines => [1..$lines] };
84 }
85 else {
86 10 content_type('text/plain');
87 10 return $paste->content;
88 }
89 10 };
90  
91  
92 10 true;
93  
94 __END__
↑ Summary script/app.pl »