Tangence/Meta/Struct.pm

filter: Statementstmt 100% 32 / 32 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 95.8% 46 / 48 CC 3 SCAR 3.5
CC
3
Cov
94%
fields
2.1
define
2.0
BEGIN
1.0
CRAP 1.4
« Tangence/Registry.pm ↑ Summary Tangence/Server/Context.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2012-2024 -- leonerd@leonerd.org.uk
5  
6 15 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Object::Pad 0.800;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 package Tangence::Meta::Struct 0.33;
11 class Tangence::Meta::Struct :strict(params);
12  
13 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 C<Tangence::Meta::Struct> - structure representing one C<Tangence> structure
18 type
19  
20 =head1 DESCRIPTION
21  
22 This data structure stores information about one L<Tangence> structure type.
23 Once constructed and defined, such objects are immutable.
24  
25 =cut
26  
27 =head1 CONSTRUCTOR
28  
29 =cut
30  
31 =head2 new
32  
33 $struct = Tangence::Meta::Struct->new( name => $name )
34  
35 Returns a new instance representing the given name.
36  
37 =cut
38  
39 12 ▶field $name :param :reader;
Subroutine name: called CC=1 SCAR=0.0
Pod documented
40 555 field $defined :reader = 0;
41  
42 555 ▶field @fields;
Subroutine defined: called CC=1 SCAR=0.0
Pod documented
43  
44 =head2 define
45  
46 $struct->define( %args )
47  
48 Provides a definition for the structure.
49  
50 =over 8
51  
52 =item fields => ARRAY
53  
54 ARRAY reference containing metadata about the structure's fields, as instances
55 of L<Tangence::Meta::Field>.
56  
57 =back
58  
59 =cut
60  
61 68 ▶method define ( %args )
Subroutine define: called CC=2 SCAR=7.0
Pod documented
62 {
63 68 ▶ $defined and croak "Cannot define $name twice";
Branch: 1 branch
BranchTrueFalseTotal
$defined and croak("Cannot define $name twice") 0 68 68
64  
65 68 $defined++;
66 68 @fields = @{ $args{fields} };
67 15 }
68  
69 =head1 ACCESSORS
70  
71 =cut
72  
73 =head2 defined
74  
75 $defined = $struct->defined
76  
77 Returns true if a definition of the structure has been provided using
78 C<define>.
79  
80 =cut
81  
82 =head2 name
83  
84 $name = $struct->name
85  
86 Returns the name of the structure
87  
88 =cut
89  
90 =head2 fields
91  
92 @fields = $struct->fields
93  
94 Returns a list of the fields defined on the structure, in their order of
95 definition.
96  
97 =cut
98  
99 method fields
100 553 ▶{
Subroutine fields: called CC=2 SCAR=7.2
Pod documented
101 553 ▶ $self->defined or croak $self->name . " is not yet defined";
Branch: 1 branch
BranchTrueFalseTotal
$self->defined or croak($self->name . ' is not yet defined') 553 0 553
102 553 return @fields;
103 15 }
104  
105 =head1 AUTHOR
106  
107 Paul Evans <leonerd@leonerd.org.uk>
108  
109 =cut
110  
111 15 0x55AA;
« Tangence/Registry.pm ↑ Summary Tangence/Server/Context.pm »