Grid/Container.pm

filter: Statementstmt 76.1% 32 / 42 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 100% 1 / 1 totaltotal 73.6% 42 / 57 CC 2 SCAR 6.5
CC
2
Cov
73%
__ANON__
6.0
__ANON__
2.0
as_string
2.0
CRAP 1.9
« Grid/Cell.pm ↑ Summary Grid/Excel/XLSX.pm »
1 package Data::Grid::Container;
2  
3 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use overload '""' => 'as_string';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Type::Params qw(multisig Invocant);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Types::Standard qw(slurpy Maybe Optional Any Int HashRef CodeRef Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 Data::Grid::Container - Generic superclass for Data::Grid containers
20  
21 =head1 VERSION
22  
23 Version 0.06
24  
25 =cut
26  
27 1 our $VERSION = '0.06';
28  
29  
30 =head1 SYNOPSIS
31  
32 package Data::Grid::Foo;
33  
34 use Moo;
35 extends 'Data::Grid::Container';
36  
37 # Now code some specific stuff...
38  
39 =head1 DESCRIPTION
40  
41 The data grid in L<Data::Grid> is modeled as an ordered tree of
42 tables, rows and cells, all contained inside a bundle. This module
43 encapsulates the common behaviour of these components.
44  
45 =head1 METHODS
46  
47 =head2 new $parent, $position [, $proxy ] | %params
48  
49 This basic constructor takes three arguments: the parent object, a
50 numeric position amongst its siblings, beginning with 0, and an
51 optional proxy object to manipulate directly, if it is necessary or
52 advantageous to do so.
53  
54 =cut
55  
56 0 ▶around BUILDARGS => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
57 0 state $check = Type::Params::multisig(
58 [CodeRef, Invocant, Object, Int, Optional[Any]],
59 [CodeRef, Invocant, slurpy HashRef],
60  
61 # this doesn't need to get checked twice
62 # [CodeRef, Invocant, slurpy Dict[parent => Object, position => Int,
63 # proxy => Optional[Maybe[Object]],
64 # slurpy Any]]
65 );
66 0 my ($orig, $class, @rest) = $check->(@_);
67  
68 # normalize parameters
69 0 my $p;
70 0 ▶ if (ref $rest[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rest[0] eq 'HASH') { } 0 0 0
71 0 $p = $rest[0];
72 }
73 else {
74 0 my @k = qw(parent position proxy);
75 0 $p = { map +($k[$_] => $rest[$_]), (0..$#k) };
76 }
77  
78 #warn Data::Dumper::Dumper($p);
79  
80 0 $class->$orig($p);
81 1 };
82  
83 =head2 parent
84  
85 Retrieve the parent object.
86  
87 =cut
88  
89 1 has parent => (
90 is => 'ro',
91 weak_ref => 1,
92 required => 1,
93 );
94  
95 =head2 position
96  
97 The position of the object in a list of its siblings, starting with 0.
98  
99 =cut
100  
101 has position => (
102 is => 'rwp',
103 0 ▶ isa => sub { Scalar::Util::looks_like_number($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 1 required => 1,
105 );
106  
107 =head2 proxy
108  
109 Whatever object or value the container is proxying.
110  
111 =cut
112  
113 1 has proxy => (
114 is => 'rwp',
115 required => 0,
116 );
117  
118 =head2 as_string
119  
120 This is a I<stub> to hook up a serialization method to the string
121 overload. Fill it in at your leisure, otherwise it is a no-op.
122  
123 =cut
124  
125 0 ▶sub as_string {
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
126 0 $_[0];
127 }
128  
129 =head1 AUTHOR
130  
131 Dorian Taylor, C<< <dorian at cpan.org> >>
132  
133 =head1 SEE ALSO
134  
135 =over 4
136  
137 =item
138  
139 L<Data::Grid>
140  
141 =item
142  
143 L<Data::Grid::Table>
144  
145 =item
146  
147 L<Data::Grid::Row>
148  
149 =item
150  
151 L<Data::Grid::Cell>
152  
153 =back
154  
155 =head1 COPYRIGHT & LICENSE
156  
157 Copyright 2010-2018 Dorian Taylor.
158  
159 Licensed under the Apache License, Version 2.0 (the "License"); you
160 may not use this file except in compliance with the License. You may
161 obtain a copy of the License at
162 L<http://www.apache.org/licenses/LICENSE-2.0>.
163  
164 Unless required by applicable law or agreed to in writing, software
165 distributed under the License is distributed on an "AS IS" BASIS,
166 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
167 implied. See the License for the specific language governing
168 permissions and limitations under the License.
169  
170 =cut
171  
172 1 1; # End of Data::Grid::Row
« Grid/Cell.pm ↑ Summary Grid/Excel/XLSX.pm »