| 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"
MC/DC0%0/1
$args->{"path"} ||= "/tmp/DirQueue"
$args->{"path"}
Truth table0%0/2
A
A= $args->{"path"}
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$config->{"hypnotoad"} and $config->{"hypnotoad"}{"user"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | next unless $dirq->lock($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | my $data = $dirq->get($name); | |||||||||||||||||||||||||||
| 35 | 0 | $dirq->remove($name); | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | return decode_json($data) if $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | next unless $dirq->lock($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | my $data = $dirq->get($name); | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | push @all, decode_json($data) if $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||