Sheets.pm

filter: Statementstmt 96.9% 63 / 65 Branchbran 100% 14 / 14 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 91.6% 22 / 24 Podpod 83.3% 5 / 6 totaltotal 94.0% 110 / 117 CC 13 SCAR 9.2
CC
13
Cov
96%
STORE
6.0
NEXTKEY
4.0
FETCH
3.0
CRAP 2.5
« Sheets/Worksheet.pm ↑ Summary
1 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use v5.42;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 package Tie::Google::Sheets 0.02 {
5  
6 # ABSTRACT: Tie perl variables to Google Sheets
7  
8 3 ▶ use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶ use List::Util qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶ use Ref::Util qw( is_plain_hashref );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶ use Tie::Google::Sheets::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶ use Tie::Google::Sheets::Worksheet;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 our @CARP_NOT = qw( Tie::Google::Sheets::Client Tie::Google::Sheets::Worksheet Class::Tiny::Object );
15  
16 3 ▶ use Class::Tiny qw( _client ), {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 17 ▶ _worksheets => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 3 };
19  
20 20 ▶ sub BUILDARGS ($class, %args) {
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod undocumented
21 return {
22 20 _client => Tie::Google::Sheets::Client->new(%args),
23 };
24 }
25  
26 20 ▶ sub TIEHASH ($class, %args) {
Subroutine TIEHASH: called CC=1 SCAR=0.0
27 20 return $class->new(%args);
28 }
29  
30 59 ▶ sub FETCH ($self, $title) {
Subroutine FETCH: called CC=3 SCAR=11.0
31 59 ▶ return $self->_worksheets->{$title} if exists $self->_worksheets->{$title};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->_worksheets->{$title} 37 22 59
32 22 ▶ return undef unless $self->EXISTS($title);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->EXISTS($title) 2 15 17
33  
34 15 my %worksheet;
35 15 tie %worksheet, 'Tie::Google::Sheets::Worksheet', client => $self->_client, title => $title;
36 15 return $self->_worksheets->{$title} = \%worksheet;
37 }
38  
39 6 ▶ sub STORE ($self, $title, $value) {
Subroutine STORE: called CC=6 SCAR=17.9
40 6 ▶ croak "worksheet '$title' already exists; assign individual cells instead, e.g. \$doc{$title}{A1} = ..."
Branch: 1 branch
BranchTrueFalseTotal
if $self->EXISTS($title) 2 4 6
41 if $self->EXISTS($title);
42 4 ▶ croak 'a new worksheet may only be assigned undef, or a hashref of cell => value pairs'
Branch: 1 branch
BranchTrueFalseTotal
if defined $value and not is_plain_hashref($value) 1 3 4
Condition100%3/3
defined $value and not is_plain_hashref($value)
!ll&&!rl&&r
121
MC/DC100%2/2
defined $value and not is_plain_hashref($value)
defined $value not is_plain_hashref($value)
Truth table100%3/3
A and not(B)
A= defined $valueB= not is_plain_hashref($value)
ABresult
0X0
100
111
43 if defined($value) && !is_plain_hashref($value);
44  
45 3 $self->_client->add_sheet($title);
46 3 delete $self->_worksheets->{$title};
47  
48 3 ▶ if(is_plain_hashref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_plain_hashref($value)) 2 1 3
49 2 my $worksheet = $self->FETCH($title);
50 2 $worksheet->{$_} = $value->{$_} for keys $value->%*;
51 }
52  
53 3 return $value;
54 }
55  
56 2 ▶ sub DELETE ($self, $title) {
Subroutine DELETE: called CC=1 SCAR=0.0
57 2 $self->_client->delete_sheet($title);
58 1 delete $self->_worksheets->{$title};
59 1 return undef;
60 }
61  
62 36 ▶ sub EXISTS ($self, $title) {
Subroutine EXISTS: called CC=1 SCAR=0.0
63 36 ▶ return !!any { $_ eq $title } $self->_client->sheet_titles->@*;
Subroutine __ANON__: called CC=1 SCAR=0.0
64 }
65  
66 2 ▶ sub CLEAR ($self) {
Subroutine CLEAR: called CC=1 SCAR=0.0
67 2 croak 'cannot delete every worksheet by clearing the tied hash (a spreadsheet must keep at least one worksheet); '
68 . 'use delete $doc{$title} to remove individual worksheets';
69 }
70  
71 2 ▶ sub FIRSTKEY ($self) {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
72 2 $self->{_iter} = $self->_client->sheet_titles;
73 2 $self->{_iter_pos} = 0;
74 2 return $self->NEXTKEY;
75 }
76  
77 5 ▶ sub NEXTKEY ($self, $lastkey = undef) {
Subroutine NEXTKEY: called CC=4 SCAR=13.9
78 5 ▶ my $titles = $self->{_iter} // [];
Condition50%1/2
$self->{"_iter"} // []
l!l
50
MC/DC0%0/1
$self->{"_iter"} // []
$self->{"_iter"}
Truth table50%1/2
A
A= $self->{"_iter"}
Aresult
11
00
79 5 ▶ return undef if $self->{_iter_pos} >= @$titles;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_iter_pos"} >= @$titles 2 3 5
80 3 return $titles->[ $self->{_iter_pos}++ ];
81 }
82  
83 2 ▶ sub add_worksheet ($self, $title, $values = undef) {
Subroutine add_worksheet: called CC=2 SCAR=6.9
Pod documented
84 2 $self->STORE($title, $values);
85 2 return $self->FETCH($title);
86 }
87  
88 0 ▶ sub delete_worksheet ($self, $title) {
Subroutine delete_worksheet: not called CC=1 SCAR=6.9
Pod documented
89 0 return $self->DELETE($title);
90 }
91  
92 3 ▶ sub copy_worksheet ($self, $from_title, $to_title) {
Subroutine copy_worksheet: called CC=2 SCAR=6.9
Pod documented
93 3 ▶ croak "worksheet '$to_title' already exists; delete it first, or choose a different name"
Branch: 1 branch
BranchTrueFalseTotal
if $self->EXISTS($to_title) 1 2 3
94 if $self->EXISTS($to_title);
95  
96 2 $self->_client->copy_worksheet($from_title, $to_title);
97 1 delete $self->_worksheets->{$to_title};
98  
99 1 return $self->FETCH($to_title);
100 }
101  
102 0 ▶ sub worksheet_titles ($self) {
Subroutine worksheet_titles: not called CC=1 SCAR=6.9
Pod documented
103 0 return $self->_client->sheet_titles->@*;
104 }
105  
106 2 ▶ sub flush ($self) {
Subroutine flush: called CC=1 SCAR=0.0
Pod documented
107 2 $self->_client->flush;
108 2 return;
109 }
110  
111 }
112  
113 __END__
« Sheets/Worksheet.pm ↑ Summary