blib/lib/Katsubushi/Client.pm

filter: Statementstmt 38.7% 19 / 49 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 54.5% 6 / 11 Podpod 0.0% 0 / 3 totaltotal 34.2% 25 / 73 CC 8 SCAR 23.1
CC
8
Cov
32%
fetch
20.0
fetch_multi
20.0
BUILD
6.0
CRAP 10.1
↑ Summary Build »
1 package Katsubushi::Client;
2  
3 3 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = "0.1";
8  
9 3 ▶use Cache::Memcached::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 use Class::Tiny +{
13 0 ▶ servers => sub { ["127.0.0.1:11212"] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 _models => sub {
15 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 return [ map {
17 0 Cache::Memcached::Fast->new({ servers => [ $_ ] });
18 0 } @{$self->servers} ];
19 },
20 3 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 sub BUILD {
23 0 ▶ my $self = shift;
Subroutine BUILD: not called CC=2 SCAR=17.9
Pod undocumented
24  
25 0 ▶ if (scalar @{$self->servers} < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->servers;} < 1) 0 0 0
26 0 die 'there are no servers.';
27 }
28 }
29  
30 sub fetch {
31 0 ▶ my $self = shift;
Subroutine fetch: not called CC=4 SCAR=30.0
Pod undocumented
32  
33 0 my $id = 0;
34  
35 # retry at once for only main (the first of list) server
36 0 for my $model ($self->_models->[0], @{$self->_models}) {
37 0 $id = $model->get('id');
38 0 ▶ last if $id;
Branch: 1 branch
BranchTrueFalseTotal
if $id 0 0 0
39 }
40  
41 0 ▶ unless ($id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 0 0 0
42 0 croak 'Failed to fetch new id';
43 }
44  
45 0 return $id;
46 }
47  
48 sub fetch_multi {
49 0 ▶ my $self = shift;
Subroutine fetch_multi: not called CC=4 SCAR=30.0
Pod undocumented
50 0 my $n = shift;
51 0 my @keys = ( 1 .. $n );
52 0 my $ids;
53 # retry at once for only main (the first of list) server
54 0 for my $model ($self->_models->[0], @{$self->_models}) {
55 0 $ids = $model->get_multi(@keys);
56 0 ▶ last if scalar(values %$ids) == $n;
Branch: 1 branch
BranchTrueFalseTotal
if scalar values %$ids == $n 0 0 0
57 }
58  
59 0 ▶ if (scalar values %$ids != $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar values %$ids != $n) 0 0 0
60 0 croak "Failed to fetch new $n ids";
61 }
62  
63 0 return map { $ids->{$_} } @keys;
64 }
65  
66 3 1;
67 __END__
↑ Summary Build »