Command/webpush.pm

filter: Statementstmt 80.6% 25 / 31 Branchbran 66.6% 4 / 6 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 80.0% 8 / 10 Podpod 100% 1 / 1 totaltotal 80.3% 41 / 51 CC 6 SCAR 11.2
CC
6
Cov
79%
__ANON__
6.0
run
5.0
_promisify
2.0
CRAP 3.1
↑ Summary Plugin/WebPush.pm »
1 package Mojolicious::Command::webpush;
2 1 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Mojo::JSON qw(encode_json decode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Crypt::PK::ECC;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 my %COMMAND2JSON = (
7 create => [ 1 ],
8 );
9 1 my %COMMAND2CB = (
10 keygen => \&_keygen,
11 );
12  
13 1 has description => q{Manage your app's web-push};
14 1 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 1 ▶sub _keygen {
Subroutine _keygen: called CC=1 SCAR=0.0
17 1 print STDOUT Crypt::PK::ECC->new->generate_key('prime256v1')
18 ->export_key_pem('private');
19 }
20  
21 0 ▶sub _promisify {
Subroutine _promisify: not called CC=1 SCAR=6.9
22 0 my ($app, $cmd) = @_;
23 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
24 0 my (undef, @args) = @_;
25 0 my @res = eval { $app->$cmd(@args) };
26 0 ▶ $@ ? Mojo::Promise->reject($@) : Mojo::Promise->resolve(@res);
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
27 0 };
28 }
29  
30 6 ▶sub run {
Subroutine run: called CC=5 SCAR=16.1
Pod documented
31 6 my ($self, $cmd, @args) = @_;
32 6 ▶ return print STDOUT $self->usage if !$cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 1 5 6
33 5 ▶ return $COMMAND2CB{$cmd}->($self, @args) if $COMMAND2CB{$cmd};
Branch: 1 branch
BranchTrueFalseTotal
if $COMMAND2CB{$cmd} 1 4 5
34 4 ▶ $args[$_] = decode_json($args[$_]) for @{ $COMMAND2JSON{$cmd} || [] };
Condition100%2/2
$COMMAND2JSON{$cmd} || []
l!l
13
MC/DC100%1/1
$COMMAND2JSON{$cmd} || []
$COMMAND2JSON{$cmd}
Truth table100%2/2
A
A= $COMMAND2JSON{$cmd}
Aresult
11
00
35 4 $cmd .= "_p";
36 $self->app->webpush->$cmd(@args)->then(
37 3 ▶ sub { print STDOUT encode_json(@_), "\n" },
Subroutine __ANON__: called CC=1 SCAR=0.0
38 1 ▶ sub { print STDERR @_, "\n" },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 4 )->wait;
40 }
41  
42 1 1;
43  
44 =encoding utf8
45  
46 =head1 NAME
47  
48 Mojolicious::Command::webpush - Manage your app's web-push
49  
50 =head1 SYNOPSIS
51  
52 Usage: APPLICATION webpush COMMAND [OPTIONS]
53  
54 ./myapp.pl webpush create <USERID> <JSON>
55 ./myapp.pl webpush read <USERID>
56 ./myapp.pl webpush delete <USERID>
57 ./myapp.pl webpush keygen > webpush_private_key.pem
58  
59 Options:
60 -h, --help Show this summary of available options
61 --home <path> Path to home directory of your application, defaults to
62 the value of MOJO_HOME or auto-detection
63 -m, --mode <name> Operating mode for your application, defaults to the
64 value of MOJO_MODE/PLACK_ENV or "development"
65  
66 =head1 DESCRIPTION
67  
68 L<Mojolicious::Command::webpush> manages your application's web-push
69 information. It gives a command-line interface to the relevant helpers
70 in L<Mojolicious::Plugin::WebPush/HELPERS>.
71  
72 The C<keygen> command prints a PEM-encoded L<Crypt::PK::ECC/generate_key>
73 C<prime256v1> result.
74  
75 =head1 ATTRIBUTES
76  
77 L<Mojolicious::Command::webpush> inherits all attributes from
78 L<Mojolicious::Command> and implements the following new ones.
79  
80 =head1 METHODS
81  
82 L<Mojolicious::Command::webpush> inherits all methods from
83 L<Mojolicious::Command> and implements the following new ones.
84  
85 =head1 SEE ALSO
86  
87 L<Mojolicious::Plugin::WebPush>
88  
89 =cut
↑ Summary Plugin/WebPush.pm »