File: Struct.pm

package info (click to toggle)
libtangence-perl 0.33-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 580 kB
  • sloc: perl: 6,076; makefile: 15
file content (111 lines) | stat: -rw-r--r-- 1,751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#  You may distribute under the terms of either the GNU General Public License
#  or the Artistic License (the same terms as Perl itself)
#
#  (C) Paul Evans, 2012-2024 -- leonerd@leonerd.org.uk

use v5.26;
use warnings;
use Object::Pad 0.800;

package Tangence::Meta::Struct 0.33;
class Tangence::Meta::Struct :strict(params);

use Carp;

=head1 NAME

C<Tangence::Meta::Struct> - structure representing one C<Tangence> structure
type

=head1 DESCRIPTION

This data structure stores information about one L<Tangence> structure type.
Once constructed and defined, such objects are immutable.

=cut

=head1 CONSTRUCTOR

=cut

=head2 new

   $struct = Tangence::Meta::Struct->new( name => $name )

Returns a new instance representing the given name.

=cut

field $name    :param :reader;
field $defined        :reader = 0;

field @fields;

=head2 define

   $struct->define( %args )

Provides a definition for the structure.

=over 8

=item fields => ARRAY

ARRAY reference containing metadata about the structure's fields, as instances
of L<Tangence::Meta::Field>.

=back

=cut

method define ( %args )
{
   $defined and croak "Cannot define $name twice";

   $defined++;
   @fields = @{ $args{fields} };
}

=head1 ACCESSORS

=cut

=head2 defined

   $defined = $struct->defined

Returns true if a definition of the structure has been provided using
C<define>.

=cut

=head2 name

   $name = $struct->name

Returns the name of the structure

=cut

=head2 fields

   @fields = $struct->fields

Returns a list of the fields defined on the structure, in their order of
definition.

=cut

method fields
{
   $self->defined or croak $self->name . " is not yet defined";
   return @fields;
}

=head1 AUTHOR

Paul Evans <leonerd@leonerd.org.uk>

=cut

0x55AA;