| 1 | package Template::Flute::Increment; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Template::Flute::Increment - Increment class for Template::Flute | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | $increment = new Template::Flute::Increment(start => 4, increment => 2); | ||
| 13 | |||
| 14 | =head1 CONSTRUCTOR | ||
| 15 | |||
| 16 | =head2 new | ||
| 17 | |||
| 18 | Create a Template::Flute::Increment object with the following parameters: | ||
| 19 | |||
| 20 | =over 4 | ||
| 21 | |||
| 22 | =item start INT | ||
| 23 | |||
| 24 | Start value for the increment. Defaults to 1. | ||
| 25 | |||
| 26 | =item increment INT | ||
| 27 | |||
| 28 | Value added to the increment with each call of the increment method. | ||
| 29 | Defaults to 1. | ||
| 30 | |||
| 31 | =back | ||
| 32 | |||
| 33 | =cut | ||
| 34 | |||
| 35 | sub new { | ||
| 36 | my ($class, $self); | ||
| 37 | my (%params); | ||
| 38 | |||
| 39 | $class = shift; | ||
| 40 | %params = @_; | ||
| 41 | |||
| 42 | # initial value | ||
| 43 | if (exists $params{start}) { | ||
| 44 | $self->{value} = $params{start}; | ||
| 45 | } | ||
| 46 | else { | ||
| 47 | $self->{value} = 1; | ||
| 48 | } | ||
| 49 | |||
| 50 | # increment | ||
| 51 | if (exists $params{increment}) { | ||
| 52 | $self->{increment} = $params{increment}; | ||
| 53 | } | ||
| 54 | else { | ||
| 55 | $self->{increment} = 1; | ||
| 56 | } | ||
| 57 | |||
| 58 | bless $self, $class; | ||
| 59 | |||
| 60 | return $self; | ||
| 61 | } | ||
| 62 | |||
| 63 | =head1 METHODS | ||
| 64 | |||
| 65 | =head2 value | ||
| 66 | |||
| 67 | Returns current value of the increment. | ||
| 68 | |||
| 69 | =cut | ||
| 70 | |||
| 71 | sub value { | ||
| 72 | my $self = shift; | ||
| 73 | |||
| 74 | return $self->{value}; | ||
| 75 | } | ||
| 76 | |||
| 77 | =head2 increment | ||
| 78 | |||
| 79 | Applies increment to value of the increment. | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | sub increment { | ||
| 84 | my $self = shift; | ||
| 85 | |||
| 86 | $self->{value} += $self->{increment}; | ||
| 87 | return $self->{value}; | ||
| 88 | } | ||
| 89 | |||
| 90 | =head1 AUTHOR | ||
| 91 | |||
| 92 | Stefan Hornburg (Racke), <racke@linuxia.de> | ||
| 93 | |||
| 94 | =head1 LICENSE AND COPYRIGHT | ||
| 95 | |||
| 96 | Copyright 2010-2016 Stefan Hornburg (Racke) <racke@linuxia.de>. | ||
| 97 | |||
| 98 | This program is free software; you can redistribute it and/or modify it | ||
| 99 | under the terms of either: the GNU General Public License as published | ||
| 100 | by the Free Software Foundation; or the Artistic License. | ||
| 101 | |||
| 102 | See http://dev.perl.org/licenses/ for more information. | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | 1; | ||
| 107 |