| 1 | package Tapper::Cmd::User; | ||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||
| 3 | 2 | $Tapper::Cmd::User::VERSION = '5.0.14'; | |||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | use Tapper::Model 'model'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use YAML::Syck; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | ▶ | use parent 'Tapper::Cmd'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | sub add | ||||||||||||||||||||
| 15 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
add: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||
| 16 | 1 | my ($self, $data) = @_; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | my $contacts = $data->{contacts}; | |||||||||||||||||||
| 19 | 1 | delete $data->{contacts}; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | ▶ | $data->{login} ||= $ENV{USER}; | ||||||||||||||||||
|
Condition33%1/3
$data->{"login"} ||= $ENV{"USER"}
MC/DC0%0/2
$data->{"login"} ||= $ENV{"USER"}
$data->{"login"}
$ENV{"USER"}
Truth table33%1/3
A ||= B
A= $data->{"login"}B= $ENV{"USER"}
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 1 | ▶ | if (not $data->{name}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | # Try to guess the real name. Since UNIX has no idea of a real name, this is extremly error prone. | ||||||||||||||||||||
| 25 | 0 | my @userdata = getpwnam($data->{login}); | |||||||||||||||||||
| 26 | 0 | $data->{name} = $userdata[6]; | |||||||||||||||||||
| 27 | 0 | $data->{name} =~ s/,//g; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 1 | my $owner = model('TestrunDB')->resultset('Owner')->new($data); | |||||||||||||||||||
| 32 | 1 | $owner->insert; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | ▶ | foreach my $contact (@{$contacts || []}) { | ||||||||||||||||||
|
Condition50%1/2
$contacts || []
MC/DC0%0/1
$contacts || []
$contacts
Truth table50%1/2
A
A= $contacts
| |||||||||||||||||||||
| 35 | 1 | $contact->{owner_id} = $owner->id; | |||||||||||||||||||
| 36 | 1 | my $contact_result = model('TestrunDB')->resultset('Contact')->new($contact); | |||||||||||||||||||
| 37 | 1 | $contact_result->insert; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 1 | return $owner->id; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | sub list | ||||||||||||||||||||
| 45 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
list: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 46 | 3 | my ($self, $search) = @_; | |||||||||||||||||||
| 47 | 3 | my @users; | |||||||||||||||||||
| 48 | 3 | my $owner_rs = model('TestrunDB')->resultset('Owner')->search($search); | |||||||||||||||||||
| 49 | 3 | ▶ | while (my $owner_result = $owner_rs->next) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 8 | my $user = { id => $owner_result->id, name => $owner_result->name, login => $owner_result->login }; | |||||||||||||||||||
| 51 | 8 | $user->{contacts} = [ map { { address => $_->address, protocol => $_->protocol } } $owner_result->contacts->all ]; | |||||||||||||||||||
| 52 | 8 | push @users, $user; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | 3 | return @users; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | sub del | ||||||||||||||||||||
| 61 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
del: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||
| 62 | 1 | my ($self, $id) = @_; | |||||||||||||||||||
| 63 | 1 | my $owner; | |||||||||||||||||||
| 64 | 1 | ▶ | if ($id =~ /^\d+$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 1 | $owner = model('TestrunDB')->resultset('Owner')->find($id); | |||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||
| 67 | 0 | $owner = model('TestrunDB')->resultset('Owner')->find({login => $id}); | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | 1 | ▶ | die qq(User "$id" not found) if not $owner;; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 1 | $owner->delete(); | |||||||||||||||||||
| 71 | 1 | return 0; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | sub contact_add | ||||||||||||||||||||
| 76 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
contact_add: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||
| 77 | 1 | my ($self, $user, $data) = @_; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 1 | ▶ | $user //= $ENV{USER}; | ||||||||||||||||||
|
Condition33%1/3
$user //= $ENV{"USER"}
MC/DC0%0/2
$user //= $ENV{"USER"}
$user
$ENV{"USER"}
Truth table33%1/3
A //= B
A= $userB= $ENV{"USER"}
| |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 1 | ▶ | if ( $user !~ m/^\d+$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 1 | my $owner_result = model('TestrunDB')->resultset('Owner')->find({login => $user}); | |||||||||||||||||||
| 83 | 1 | ▶ | die "User $user does not exist in database\n" if not $owner_result; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 1 | $user = $owner_result->id; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | 1 | ▶ | $data->{owner_id} ||= $user; | ||||||||||||||||||
|
Condition33%1/3
$data->{"owner_id"} ||= $user
MC/DC0%0/2
$data->{"owner_id"} ||= $user
$data->{"owner_id"}
$user
Truth table33%1/3
A ||= B
A= $data->{"owner_id"}B= $user
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 1 | my $contact = model('TestrunDB')->resultset('Contact')->new($data); | |||||||||||||||||||
| 89 | 1 | $contact->insert; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 1 | return $contact->id; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 2 | 1; # End of Tapper::Cmd::Testrun | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||