blib/lib/Mojolicious/Plugin/DirectoryQueue.pm

filter: Statementstmt 31.8% 14 / 44 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 40.0% 4 / 10 Podpod 100% 1 / 1 totaltotal 24.6% 19 / 77 CC 10 SCAR 25.8
CC
10
Cov
22%
register
20.0
__ANON__
20.0
__ANON__
20.0
CRAP 13.2
↑ Summary
1 package Mojolicious::Plugin::DirectoryQueue;
2  
3 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mojo::JSON qw(decode_json encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Directory::Queue;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use POSIX qw(chown);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.01';
9  
10  
11 0 ▶sub register {
Subroutine register: not called CC=4 SCAR=30.0
Pod documented
12 0 my ($plugin, $app, $args) = @_;
13  
14 0 ▶ $args->{path} ||= '/tmp/DirQueue';
Condition0%0/2
$args->{"path"} ||= "/tmp/DirQueue"
l!l
00
MC/DC0%0/1
$args->{"path"} ||= "/tmp/DirQueue"
$args->{"path"}
Truth table0%0/2
A
A= $args->{"path"}
Aresult
11
00
15 0 my $dirq = Directory::Queue->new( path => $args->{path} );
16  
17 0 my $config = $app->config;
18 0 ▶ if ( $config->{hypnotoad} and $config->{hypnotoad}->{user} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"hypnotoad"} and $config->{"hypnotoad"}{"user"}) 0 0 0
Condition0%0/3
$config->{"hypnotoad"} and $config->{"hypnotoad"}{"user"}
!ll&&!rl&&r
000
MC/DC0%0/2
$config->{"hypnotoad"} and $config->{"hypnotoad"}{"user"}
$config->{"hypnotoad"} $config->{"hypnotoad"}{"user"}
Truth table0%0/3
A and B
A= $config->{"hypnotoad"}B= $config->{"hypnotoad"}{"user"}
ABresult
0X0
100
111
19 0 my ($uid,$gid) = ( getpwnam($config->{hypnotoad}->{user}) )[2,3];
20 0 chown $uid, $gid, $args->{path};
21 }
22  
23 $app->helper(
24 0 ▶ enqueue => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 0 my ($self, $args) = @_;
26 0 $dirq->add(encode_json($args));
27 },
28 0 );
29  
30 $app->helper(
31 0 ▶ dequeue => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
32 0 ▶ for (my $name = $dirq->first(); $name; $name = $dirq->next()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
33 0 ▶ next unless $dirq->lock($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $dirq->lock($name) 0 0 0
34 0 my $data = $dirq->get($name);
35 0 $dirq->remove($name);
36 0 ▶ return decode_json($data) if $data;
Branch: 1 branch
BranchTrueFalseTotal
if $data 0 0 0
37 }
38 0 return;
39 },
40 0 );
41  
42 $app->helper(
43 0 ▶ show => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
44 0 my @all;
45 0 ▶ for (my $name = $dirq->first(); $name; $name = $dirq->next()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
46 0 ▶ next unless $dirq->lock($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $dirq->lock($name) 0 0 0
47 0 my $data = $dirq->get($name);
48 0 ▶ push @all, decode_json($data) if $data;
Branch: 1 branch
BranchTrueFalseTotal
if $data 0 0 0
49 0 $dirq->unlock($name);
50 }
51 0 return \@all;
52 },
53 0 );
54  
55 $app->helper(
56 0 ▶ count => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 return $dirq->count();
58 },
59 0 );
60 $app->helper(
61 0 ▶ purge => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 0 my $self = shift;
63 0 return $dirq->purge(@_);
64 },
65 0 );
66 };
67  
68 1 1;
69 __END__
↑ Summary