File Coverage

blib/lib/Data/FSM/State.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 30 31 96.7


line stmt bran cond sub pod time code
1             package Data::FSM::State;
2              
3 16     16   171085 use strict;
  16         36  
  16         609  
4 16     16   149 use warnings;
  16         30  
  16         971  
5              
6 16     16   6537 use Mo qw(build is);
  16         8278  
  16         109  
7 16     16   35591 use Mo::utils 0.06 qw(check_bool check_length);
  16         246559  
  16         421  
8 16     16   10829 use Mo::utils::Number qw(check_positive_natural);
  16         34709  
  16         904  
9              
10             our $VERSION = 0.01;
11              
12             has id => (
13             is => 'ro',
14             );
15              
16             has initial => (
17             is => 'ro',
18             );
19              
20             has name => (
21             is => 'ro',
22             );
23              
24             sub BUILD {
25 50     50 0 3689771 my $self = shift;
26              
27             # Check 'id'.
28 50         289 check_positive_natural($self, 'id');
29              
30             # Check 'inital'.
31 47 100       706 if (! defined $self->{'initial'}) {
32 31         102 $self->{'initial'} = 0;
33             }
34 47         211 check_bool($self, 'initial');
35              
36             # Check 'name'.
37 46         1021 check_length($self, 'name', 100);
38              
39 45         572 return;
40             }
41              
42             1;
43              
44             __END__
45              
46             =pod
47              
48             =encoding utf8
49              
50             =head1 NAME
51              
52             Data::FSM::State - Data object for Finite State Machine state.
53              
54             =head1 SYNOPSIS
55              
56             use Data::FSM::State;
57              
58             my $obj = Data::FSM::State->new(%params);
59             my $id = $obj->id;
60             my $initial = $obj->initial;
61             my $name = $obj->name;
62              
63             =head1 METHODS
64              
65             =head2 C<new>
66              
67             my $obj = Data::FSM::State->new(%params);
68              
69             Constructor.
70              
71             =over 8
72              
73             =item * C<id>
74              
75             FSM state id.
76             The id is positive natural number.
77              
78             It's optional.
79              
80             Default value is undef.
81              
82             =item * C<initial>
83              
84             FSM state initial flag.
85              
86             Default value is 0.
87              
88             =item * C<name>
89              
90             FSM state name.
91             The length of name is 100 characters.
92              
93             Default value is undef.
94              
95             =back
96              
97             Returns instance of object.
98              
99             =head2 C<id>
100              
101             my $id = $obj->id;
102              
103             Get FSM state id.
104              
105             Returns positive natural number.
106              
107             =head2 C<initial>
108              
109             my $initial = $obj->initial;
110              
111             Get inital flag..
112              
113             Returns boolean (0/1).
114              
115             =head2 C<name>
116              
117             my $name = $obj->name;
118              
119             Get FSM state name.
120              
121             Returns string.
122              
123             =head1 ERRORS
124              
125             new():
126             From Mo::Utils::check_bool():
127             Parameter 'initial' must be a bool (0/1).
128             Value: %s
129              
130             From Mo::Utils::check_length():
131             Parameter 'name' has length greater than '100'.
132             Value: %s
133              
134             From Mo::utils::Number::check_positive_natural():
135             Parameter 'id' must be a positive natural number.
136             Value: %s
137              
138             =head1 EXAMPLE
139              
140             =for comment filename=create_and_print_fsm_state.pl
141              
142             use strict;
143             use warnings;
144              
145             use Data::FSM::State;
146              
147             my $obj = Data::FSM::State->new(
148             'id' => 7,
149             'initial' => 0,
150             'name' => 'From',
151             );
152              
153             # Print out.
154             print 'Id: '.$obj->id."\n";
155             print 'Initial: '.$obj->initial."\n";
156             print 'Name: '.$obj->name."\n";
157              
158             # Output:
159             # Id: 7
160             # Initial: 0
161             # Name: From
162              
163             =head1 DEPENDENCIES
164              
165             L<Mo>,
166             L<Mo::utils>,
167             L<Mo::utils::Number>.
168              
169             =head1 REPOSITORY
170              
171             L<https://github.com/michal-josef-spacek/Data-FSM>
172              
173             =head1 AUTHOR
174              
175             Michal Josef Špaček L<mailto:skim@cpan.org>
176              
177             L<http://skim.cz>
178              
179             =head1 LICENSE AND COPYRIGHT
180              
181             © 2025-2026 Michal Josef Špaček
182              
183             BSD 2-Clause License
184              
185             =head1 VERSION
186              
187             0.01
188              
189             =cut