File Coverage

blib/lib/Graph/PetriNet/PlaceAble.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Graph::PetriNet::PlaceAble;
2              
3 1     1   6778 use Class::Trait 'base';
  0            
  0            
4              
5             our @REQUIRES = qw();
6              
7             =pod
8              
9             =head1 NAME
10              
11             Graph::PetriNet::PlaceAble - Trait for Petri net data nodes
12              
13             =head1 SYNOPSIS
14              
15             # create your own data nodes with this trait
16             {
17             package My::Place::TimeDepend;
18             use Class::Trait qw(Graph::PetriNet::PlaceAble);
19              
20             sub new {
21             my $class = shift;
22             return bless { ..., ... }, $class;
23             }
24             sub .... {
25             ...
26             }
27             }
28              
29             =head1 DESCRIPTION
30              
31             Petri net data nodes are supposed to carry the information within the Petri net. What information
32             this is, the Petri net does not care.
33              
34             The default behavior implemented here is the I interpretation of every node having
35             I. Accordingly there is a method to set/read the number of tokens and one method to
36             increment/decrement that.
37              
38             If your transitions do something completely different, then you will implement your own data nodes
39             without importing any of the functionality here.
40              
41             =head1 TRAIT
42              
43             =head2 Methods
44              
45             =over
46              
47             =item B
48              
49             Getter/setter method for the number of tokens in this node.
50              
51             =cut
52              
53             sub tokens {
54             my $self = shift;
55             my $tokens = shift;
56             return defined $tokens ? $self->{_tokens} = $tokens : $self->{_tokens};
57             }
58              
59             =pod
60              
61             =item B
62              
63             This method expects one integer parameter (positive or negative). Its value
64             is added to the number of tokens. The result will be corrected to zero.
65              
66             =cut
67              
68             sub incr_tokens {
69             my $self = shift;
70             my $delta = shift;
71             $self->{_tokens} += $delta;
72             $self->{_tokens} = 0 if $self->{_tokens} < 0;
73             }
74              
75             =pod
76              
77             =back
78              
79             =head1 SEE ALSO
80              
81             L
82              
83             =head1 AUTHOR
84              
85             Robert Barta, Edrrho@cpan.orgE
86              
87             =head1 COPYRIGHT AND LICENSE
88              
89             Copyright (C) 2009 by Robert Barta
90              
91             This library is free software; you can redistribute it and/or modify it under the same terms as Perl
92             itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have
93             available.
94              
95              
96             =cut
97              
98             "against all gods";