| 1 | package Graph::PetriNet::PlaceAble; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use Class::Trait 'base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | 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<classical> interpretation of every node having | ||||||||||
| 35 | I<tokens>. 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<tokens> | ||||||||||
| 48 | |||||||||||
| 49 | Getter/setter method for the number of tokens in this node. | ||||||||||
| 50 | |||||||||||
| 51 | =cut | ||||||||||
| 52 | |||||||||||
| 53 | 191 | ▶ | sub tokens { | ||||||||
|
Subroutine
tokens: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 54 | 191 | my $self = shift; | |||||||||
| 55 | 191 | my $tokens = shift; | |||||||||
| 56 | 191 | ▶ | return defined $tokens ? $self->{_tokens} = $tokens : $self->{_tokens}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | =pod | ||||||||||
| 60 | |||||||||||
| 61 | =item B<incr_tokens> | ||||||||||
| 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 | 29 | ▶ | sub incr_tokens { | ||||||||
|
Subroutine
incr_tokens: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 69 | 29 | my $self = shift; | |||||||||
| 70 | 29 | my $delta = shift; | |||||||||
| 71 | 29 | $self->{_tokens} += $delta; | |||||||||
| 72 | 29 | ▶ | $self->{_tokens} = 0 if $self->{_tokens} < 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | =pod | ||||||||||
| 76 | |||||||||||
| 77 | =back | ||||||||||
| 78 | |||||||||||
| 79 | =head1 SEE ALSO | ||||||||||
| 80 | |||||||||||
| 81 | L<Graph::PetriNet> | ||||||||||
| 82 | |||||||||||
| 83 | =head1 AUTHOR | ||||||||||
| 84 | |||||||||||
| 85 | Robert Barta, E<lt>drrho@cpan.orgE<gt> | ||||||||||
| 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 | 3 | "against all gods"; | |||||||||