| 1 | package Tapper::Cmd::Notification; | ||||||||||||||||||||
| 2 | 8 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||
| 3 | 8 | $Tapper::Cmd::Notification::VERSION = '5.0.14'; | |||||||||||||||||||
| 4 | 8 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 8 | ▶ | use Tapper::Model 'model'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 8 | ▶ | use YAML::Syck; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 8 | ▶ | use parent 'Tapper::Cmd'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | sub get_user | ||||||||||||||||||||
| 14 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_user: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||
| 15 | 3 | my ($self, $data) = @_; | |||||||||||||||||||
| 16 | 3 | ▶ | if (not $data->{owner_id}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | 2 | ▶ | my $login = $data->{owner_login} || $ENV{USER}; | ||||||||||||||||||
|
Condition33%1/3
$data->{'owner_login'} || $ENV{'USER'}
MC/DC0%0/2
$data->{'owner_login'} || $ENV{'USER'}
$data->{'owner_login'}
$ENV{'USER'}
Truth table33%1/3
A || B
A= $data->{'owner_login'}B= $ENV{'USER'}
| |||||||||||||||||||||
| 18 | 2 | my $owner = model('TestrunDB')->resultset('Owner')->search({login => $login}, {rows => 1})->first; | |||||||||||||||||||
| 19 | 2 | ▶ | if (not $owner) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 0 | die "User '$login' does not exist in the database. Please create this user first.\n"; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 2 | $data->{owner_id} = $owner->id; | |||||||||||||||||||
| 24 | 2 | delete $data->{owner_login}; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | 3 | return $data; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | ▶ | sub add { | ||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 33 | 2 | my ($self, $data) = @_; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 2 | $data = $self->get_user($data); | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 2 | my $notification = model('TestrunDB')->resultset('Notification')->new($data); | |||||||||||||||||||
| 38 | 2 | $notification->insert; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 2 | return $notification->id; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | sub list | ||||||||||||||||||||
| 45 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 46 | 0 | my ($self, $search) = @_; | |||||||||||||||||||
| 47 | 0 | return model('TestrunDB')->resultset('Notification')->search($search, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }); | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 1 | ▶ | sub update { | ||||||||||||||||||
|
Subroutine
update: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||
| 53 | 1 | my ($self, $id, $data) = @_; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 1 | my $notification = model('TestrunDB')->resultset('Notification')->find($id); | |||||||||||||||||||
| 56 | 1 | ▶ | die "Notification subscription with id $id not found\n" if not $notification; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 1 | ▶ | die "Did not get a hash with data for updating notification subscription with id '$id'" unless ref $data eq 'HASH'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 1 | $data = $self->get_user($data); | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 1 | foreach my $key (keys %$data) { | |||||||||||||||||||
| 63 | 5 | $notification->$key($data->{$key}); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | 1 | $notification->update; | |||||||||||||||||||
| 66 | 1 | return $notification->id; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 1 | ▶ | sub del { | ||||||||||||||||||
|
Subroutine
del: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 72 | 1 | my ($self, $id) = @_; | |||||||||||||||||||
| 73 | 1 | my $notification = model('TestrunDB')->resultset('Notification')->find($id); | |||||||||||||||||||
| 74 | 1 | ▶ | die qq(No notification subscription with id "$id" found) if not $notification;; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 1 | $notification->delete(); | |||||||||||||||||||
| 76 | 1 | return 0; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 8 | 1; # End of Tapper::Cmd::Testrun | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||