blib/lib/Tapper/CLI/Notification.pm

filter: Statementstmt 71.5% 68 / 95 Branchbran 55.0% 11 / 20 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 5 / 5 totaltotal 66.4% 95 / 143 CC 15 SCAR 17.5
CC
15
Cov
66%
notificationnew
9.6
notificationdel
6.3
notificationupdate
5.8
CRAP 5.7
« blib/lib/Tapper/CLI/DbDeploy/Command/init.pm ↑ Summary blib/lib/Tapper/CLI/Utils.pm »
1 package Tapper::CLI::Notification;
2 72 our $AUTHORITY = 'cpan:TAPPER';
3 72 $Tapper::CLI::Notification::VERSION = '5.0.8';
4 72 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 72 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 72 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 sub notificationnew
10 1 ▶{
Subroutine notificationnew: called CC=7 SCAR=22.6
Pod documented
11 1 my ($c) = @_;
12 1 $c->getopt( 'file|f=s', 'user|u=s','quiet|q', 'help|?', 'verbose|v' );
13  
14 1 ▶ if (not %{$c->options} or $c->options->{help} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %{$c->options;} or $c->options->{"help"}) 0 1 1
Condition33%1/3
not %{$c->options;} or $c->options->{"help"}
l!l&&r!l&&!r
001
MC/DC0%0/2
not %{$c->options;} or $c->options->{"help"}
not %{$c->options;} $c->options->{"help"}
Truth table33%1/3
not(A) or B
A= not %{$c->options;}B= $c->options->{"help"}
ABresult
1X1
011
000
15 0 say STDERR "Usage: $0 notification-add --file=filename [ --user=login ] [ --quiet ]";
16 0 say STDERR "\n\ Required Arguments:";
17 0 say STDERR " --file name of file containing the notification subscriptions in YAML (required)";
18 0 say STDERR "\n Optional arguments:";
19 0 say STDERR " --user set this user for all notification subscriptions (even if a different one is set in YAML)";
20 0 say STDERR " --verbose Be chatty";
21 0 say STDERR " --quiet Stay silent when notification was added";
22 0 say STDERR " --help print this help message and exit";
23 0 return;
24 }
25  
26 1 require Tapper::Cmd::Notification;
27 1 my $cmd = Tapper::Cmd::Notification->new();
28 1 my $user = $c->options->{user};
29  
30 1 my @ids;
31 1 require YAML::XS;
32 1 my @subscriptions = YAML::XS::LoadFile($c->options->{file});
33 1 foreach my $subscription (@subscriptions) {
34 1 ▶ if ($user) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user) 1 0 1
35 1 $subscription->{owner_login} = $user;
36 1 delete $subscription->{owner_id};
37 }
38 1 push @ids, $cmd->add($subscription);
39 }
40 1 my $msg;
41 1 ▶ if (not $c->options->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->options->{"quiet"}) 1 0 1
42 1 ▶ $msg = "The notification subscriptions were registered with the following ids:" if $c->options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $c->options->{"verbose"} 0 1 1
43 1 $msg .= join ",", @ids;
44 }
45 1 return $msg;
46 }
47  
48  
49 sub notificationlist
50 3 ▶{
Subroutine notificationlist: called CC=2 SCAR=6.9
Pod documented
51 3 my ($c) = @_;
52  
53 3 require YAML::XS;
54 3 require Tapper::Cmd::Notification;
55  
56 3 my $cmd = Tapper::Cmd::Notification->new();
57 3 my $subscription_result = $cmd->list();
58 3 ▶ while (my $this_subscription = $subscription_result->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_subscription = $subscription_result->next) 2 3 5
59 2 delete $this_subscription->{created_at};
60 2 delete $this_subscription->{updated_at};
61 2 print YAML::XS::Dump($this_subscription);
62 }
63 3 return;
64 }
65  
66  
67 sub notificationupdate
68 1 ▶{
Subroutine notificationupdate: called CC=4 SCAR=17.6
Pod documented
69 1 my ($c) = @_;
70 1 $c->getopt( 'file|f=s', 'id|i=i','quiet|q', 'help|?' );
71  
72 1 ▶ if (not %{$c->options} or $c->options->{help} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %{$c->options;} or $c->options->{"help"}) 0 1 1
Condition33%1/3
not %{$c->options;} or $c->options->{"help"}
l!l&&r!l&&!r
001
MC/DC0%0/2
not %{$c->options;} or $c->options->{"help"}
not %{$c->options;} $c->options->{"help"}
Truth table33%1/3
not(A) or B
A= not %{$c->options;}B= $c->options->{"help"}
ABresult
1X1
011
000
73 0 say STDERR "Usage: $0 notification-update --file=filename --id=id [ --quiet ]";
74 0 say STDERR "\n\ Required Arguments:";
75 0 say STDERR " --file name of file containing the notification subscriptions in YAML";
76 0 say STDERR " --id id of the notification subscriptions";
77 0 say STDERR "\n Optional arguments:";
78 0 say STDERR " --quiet stay silent when notification was updated";
79 0 say STDERR " --help print this help message and exit";
80 0 return;
81 }
82  
83 1 require Tapper::Cmd::Notification;
84 1 my $cmd = Tapper::Cmd::Notification->new();
85  
86 1 require YAML::XS;
87 1 my $subscription = YAML::XS::LoadFile($c->options->{file});
88 1 my $id = $cmd->update($c->options->{id}, $subscription);
89  
90 1 ▶ if ( not $c->options->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->options->{"quiet"}) 1 0 1
91 1 return $id;
92 }
93 0 return;
94 }
95  
96  
97 sub notificationdel
98 1 ▶{
Subroutine notificationdel: called CC=4 SCAR=18.4
Pod documented
99 1 my ($c) = @_;
100 1 $c->getopt( 'id|i=i','quiet|q', 'help|?' );
101  
102 1 ▶ if (not %{$c->options} or $c->options->{help} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %{$c->options;} or $c->options->{"help"}) 0 1 1
Condition33%1/3
not %{$c->options;} or $c->options->{"help"}
l!l&&r!l&&!r
001
MC/DC0%0/2
not %{$c->options;} or $c->options->{"help"}
not %{$c->options;} $c->options->{"help"}
Truth table33%1/3
not(A) or B
A= not %{$c->options;}B= $c->options->{"help"}
ABresult
1X1
011
000
103 0 say STDERR "Usage: $0 notification-del --id=id";
104 0 say STDERR "\n\ Required Arguments:";
105 0 say STDERR " --id Database ID of the notification subscription";
106 0 say STDERR "\n Optional arguments:";
107 0 say STDERR " --quiet Stay silent when deleting succeeded";
108 0 say STDERR " --help print this help message and exit";
109 0 return;
110 }
111  
112 1 require Tapper::Cmd::Notification;
113 1 my $cmd = Tapper::Cmd::Notification->new();
114  
115 1 my $id = $cmd->del($c->options->{id});
116  
117 1 ▶ return "The notification subscription was deleted." unless $c->options->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $c->options->{"quiet"} 1 0 1
118 0 return;
119 }
120  
121  
122  
123  
124 sub setup
125 71 ▶{
Subroutine setup: called CC=2 SCAR=7.1
Pod documented
126 71 my ($c) = @_;
127 71 $c->register('notification-add', \&notificationnew, 'Register a new notification subscription');
128 71 $c->register('notification-new', \&notificationnew, 'Alias for notification-add');
129 71 $c->register('notification-list', \&notificationlist, 'Show all notification subscriptions');
130 71 $c->register('notification-update', \&notificationupdate, 'Update an existing notification subscription');
131 71 $c->register('notification-del', \&notificationdel, 'Delete an existing notification subscription');
132 71 ▶ if ($c->can('group_commands')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->can("group_commands")) 0 71 71
133 0 $c->group_commands(
134 'Notification commands',
135 'notification-add',
136 'notification-new',
137 'notification-list',
138 'notification-update',
139 'notification-del',
140 );
141 }
142 71 return;
143 }
144  
145 72 1; # End of Tapper::CLI
146  
147 __END__
« blib/lib/Tapper/CLI/DbDeploy/Command/init.pm ↑ Summary blib/lib/Tapper/CLI/Utils.pm »