File Coverage

blib/lib/Tangence/Meta/Property.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 5 5 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
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, 2011-2024 -- leonerd@leonerd.org.uk
5              
6 15     15   298 use v5.26;
  15         68  
7 15     15   89 use warnings;
  15         31  
  15         964  
8 15     15   112 use Object::Pad 0.800;
  15         129  
  15         755  
9              
10             package Tangence::Meta::Property 0.33;
11             class Tangence::Meta::Property :strict(params);
12              
13 15     15   8697 use Syntax::Keyword::Match;
  15         12018  
  15         122  
14              
15 15     15   1645 use Tangence::Constants;
  15         130  
  15         26526  
16              
17             =head1 NAME
18              
19             C - structure representing one C property
20              
21             =head1 DESCRIPTION
22              
23             This data structure object stores information about one L class
24             property. Once constructed, such objects are immutable.
25              
26             =cut
27              
28             =head1 CONSTRUCTOR
29              
30             =cut
31              
32             =head2 new
33              
34             $property = Tangence::Meta::Property->new( %args )
35              
36             Returns a new instance initialised by the given arguments.
37              
38             =over 8
39              
40             =item class => Tangence::Meta::Class
41              
42             Reference to the containing class
43              
44             =item name => STRING
45              
46             Name of the property
47              
48             =item dimension => INT
49              
50             Dimension of the property, as one of the C constants from
51             L.
52              
53             =item type => STRING
54              
55             The element type as a L reference.
56              
57             =item smashed => BOOL
58              
59             Optional. If true, marks that the property is smashed.
60              
61             =back
62              
63             =cut
64              
65 1     1 1 788 field $class :param :weak :reader;
  1         8  
66 124     124 1 2847 field $name :param :reader;
  124         446  
67 480     480 1 1280 field $dimension :param :reader;
  480         1652  
68 272     272 1 741 field $type :param :reader;
  272         1204  
69 192     192 1 397 field $smashed :param :reader = 0;
70              
71 192         698 =head1 ACCESSORS
72              
73             =cut
74              
75             =head2 class
76              
77             $class = $property->class
78              
79             Returns the class the property is a member of
80              
81             =cut
82              
83             =head2 name
84              
85             $name = $property->name
86              
87             Returns the name of the class
88              
89             =cut
90              
91             =head2 dimension
92              
93             $dimension = $property->dimension
94              
95             Returns the dimension as one of the C constants.
96              
97             =cut
98              
99             =head2 type
100              
101             $type = $property->type
102              
103             Returns the element type as a L reference.
104              
105             =cut
106              
107             =head2 overall_type
108              
109             $type = $property->overall_type
110              
111             Returns the type of the entire collection as a L
112             reference. For scalar types this will be the element type. For dict types this
113             will be a hash of the array type. For array, queue and objset types this will
114             a list of the element type.
115              
116             =cut
117              
118             field $_overall_type;
119              
120             method overall_type
121             {
122             return $_overall_type ||= do {
123             my $type = $self->type;
124             my $dim = $self->dimension;
125             match( $dim : == ) {
126             case( DIM_SCALAR ) {
127             $type;
128             }
129             case( DIM_HASH ) {
130             $self->make_type( dict => $type );
131             }
132             case( DIM_ARRAY ), case( DIM_QUEUE ), case( DIM_OBJSET ) {
133             $self->make_type( list => $type );
134             }
135             default {
136             die "Unrecognised dimension $dim for ->overall_type";
137             }
138             }
139             }
140             }
141              
142             =head2 smashed
143              
144             $smashed = $property->smashed
145              
146             Returns true if the property is smashed.
147              
148             =cut
149              
150             # For subclasses to override if required
151             method make_type
152             {
153             return Tangence::Meta::Type->make( @_ );
154             }
155              
156             =head1 AUTHOR
157              
158             Paul Evans
159              
160             =cut
161              
162             0x55AA;
163