| 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 | ▶ | 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::Property 0.33; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | class Tangence::Meta::Property :strict(params); | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use Syntax::Keyword::Match; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | ▶ | use Tangence::Constants; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | C<Tangence::Meta::Property> - structure representing one C<Tangence> property | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | This data structure object stores information about one L<Tangence> 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<DIM_*> constants from | ||||||||||||||||||||||||||||||||||||||||||
| 51 | L<Tangence::Constants>. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | =item type => STRING | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | The element type as a L<Tangence::Meta::Type> 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 | ▶ | field $class :param :weak :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 124 | ▶ | field $name :param :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 480 | ▶ | field $dimension :param :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dimension: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 272 | ▶ | field $type :param :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 192 | field $smashed :param :reader = 0; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 192 | ▶ | =head1 ACCESSORS | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
smashed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 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<DIM_*> constants. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | =head2 type | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | $type = $property->type | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | Returns the element type as a L<Tangence::Meta::Type> 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<Tangence::Meta::Type> | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 15 | field $_overall_type; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | method overall_type | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 90 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
overall_type: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 90 | ▶ | return $_overall_type ||= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_overall_type ||= do {
my $type = $self->type;
my $dim = $self->dimension;
do {
my $(Syntax::Keyword::Match/topic) = $dim;
$(Syntax::Keyword::Match/topic) == 1 ? do {
$type
} : ($(Syntax::Keyword::Match/topic) == 2 ? do {
$self->make_type("dict", $type)
} : ($(Syntax::Keyword::Match/topic) == 4 || $(Syntax::Keyword::Match/topic) == 3 || $(Syntax::Keyword::Match/topic) == 5 ? do {
$self->make_type("list", $type)
} : do {
die "Unrecognised dimension $dim for ->overall_type"
}))
}
}
MC/DC0%0/2
$_overall_type ||= do {
my $type = $self->type;
my $dim = $self->dimension;
do {
my $(Syntax::Keyword::Match/topic) = $dim;
$(Syntax::Keyword::Match/topic) == 1 ? do {
$type
} : ($(Syntax::Keyword::Match/topic) == 2 ? do {
$self->make_type("dict", $type)
} : ($(Syntax::Keyword::Match/topic) == 4 || $(Syntax::Keyword::Match/topic) == 3 || $(Syntax::Keyword::Match/topic) == 5 ? do {
$self->make_type("list", $type)
} : do {
die "Unrecognised dimension $dim for ->overall_type"
}))
}
}
$_overall_type
do {
my $type = $self->type;
my $dim = $self->dimension;
do {
my $(Syntax::Keyword::Match/topic) = $dim;
$(Syntax::Keyword::Match/topic) == 1 ? do {
$type
} : ($(Syntax::Keyword::Match/topic) == 2 ? do {
$self->make_type("dict", $type)
} : ($(Syntax::Keyword::Match/topic) == 4 || $(Syntax::Keyword::Match/topic) == 3 || $(Syntax::Keyword::Match/topic) == 5 ? do {
$self->make_type("list", $type)
} : do {
die "Unrecognised dimension $dim for ->overall_type"
}))
}
}
Truth table66%2/3
A ||= B
A= $_overall_typeB= do {
my $type = $self->type;
my $dim = $self->dimension;
do {
my $(Syntax::Keyword::Match/topic) = $dim;
$(Syntax::Keyword::Match/topic) == 1 ? do {
$type
} : ($(Syntax::Keyword::Match/topic) == 2 ? do {
$self->make_type("dict", $type)
} : ($(Syntax::Keyword::Match/topic) == 4 || $(Syntax::Keyword::Match/topic) == 3 || $(Syntax::Keyword::Match/topic) == 5 ? do {
$self->make_type("list", $type)
} : do {
die "Unrecognised dimension $dim for ->overall_type"
}))
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 61 | my $type = $self->type; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 61 | my $dim = $self->dimension; | |||||||||||||||||||||||||||||||||||||||||
| 125 | match( $dim : == ) { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | case( DIM_SCALAR ) { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 30 | ▶ | $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | case( DIM_HASH ) { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | ▶ | $self->make_type( dict => $type ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$(Syntax::Keyword::Match/topic) == 4 or $(Syntax::Keyword::Match/topic) == 3 or $(Syntax::Keyword::Match/topic) == 5
$(Syntax::Keyword::Match/topic) == 4 or $(Syntax::Keyword::Match/topic) == 3
MC/DC0%0/3
$(Syntax::Keyword::Match/topic) == 4 or $(Syntax::Keyword::Match/topic) == 3 or $(Syntax::Keyword::Match/topic) == 5
$(Syntax::Keyword::Match/topic) == 4
$(Syntax::Keyword::Match/topic) == 3
$(Syntax::Keyword::Match/topic) == 5
Truth table75%3/4
A or B or C
A= $(Syntax::Keyword::Match/topic) == 4B= $(Syntax::Keyword::Match/topic) == 3C= $(Syntax::Keyword::Match/topic) == 5
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | case( DIM_ARRAY ), case( DIM_QUEUE ), case( DIM_OBJSET ) { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 27 | $self->make_type( list => $type ); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 61 | ▶ | default { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | die "Unrecognised dimension $dim for ->overall_type"; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 15 | } | |||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return Tangence::Meta::Type->make( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 15 | } | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 15 | 0x55AA; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||