Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add WellWell::Zoom::Increment class.
  • Loading branch information
racke committed Sep 6, 2010
1 parent 6d51f0e commit a16fb33
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/WellWell/Zoom.pm
Expand Up @@ -25,6 +25,8 @@ use warnings;
use XML::Twig;
use Rose::DB::Object::QueryBuilder qw(build_select);

use WellWell::Zoom::Increment;

use Vend::Config;
use Vend::Data;
use Vend::Tags;
Expand Down Expand Up @@ -87,6 +89,10 @@ sub zoom {
while (($key, $value) = each %{$sref->{params}->{$name}->{hash}}) {
$rep_str = $row->{$value->{field} || $key};

if ($value->{increment}) {
$rep_str = $value->{increment}->value();
}

if ($value->{subref}) {
$rep_str = $value->{subref}->($row);
}
Expand Down Expand Up @@ -118,6 +124,11 @@ sub zoom {
my $subtree = $lel->copy();

$subtree->paste(%paste_pos);

# call increment functions
for my $inc (@{$sref->{increments}->{$name}->{array}}) {
$inc->{increment}->increment();
}
}

# replacements for simple values
Expand Down Expand Up @@ -217,6 +228,17 @@ sub parse_handler {
$sref->{params}->{$sob->{list}}->{hash}->{$name} = $sob;
push(@{$sref->{params}->{$sob->{list}}->{array}}, $sob);
}
elsif ($sob->{type} eq 'increment') {
# increments
push (@{$sob->{elts}}, $elt);

# create increment object and record it for increment updates
$sob->{increment} = new WellWell::Zoom::Increment;
push(@{$sref->{increments}->{$sob->{list}}->{array}}, $sob);

# record it for increment values
$sref->{params}->{$sob->{list}}->{hash}->{$name} = $sob;
}
elsif ($sob->{type} eq 'value') {
push (@{$sob->{elts}}, $elt);
$sref->{values}->{$name} = $sob;
Expand Down
67 changes: 67 additions & 0 deletions lib/WellWell/Zoom/Increment.pm
@@ -0,0 +1,67 @@
# WellWell::Zoom::Increment - WellWell increment objects
#
# Copyright (C) 2010 Stefan Hornburg (Racke) <racke@linuxia.de>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

package WellWell::Zoom::Increment;

use strict;
use warnings;

sub new {
my ($class, $self);
my (%params);

$class = shift;
%params = @_;

# initial value
if (exists $params{start}) {
$self->{value} = $params{start};
}
else {
$self->{value} = 1;
}

# increment
if (exists $params{increment}) {
$self->{increment} = $params{increment};
}
else {
$self->{increment} = 1;
}

bless $self;

return $self;
}

sub value {
my $self = shift;

return $self->{value};
}

sub increment {
my $self = shift;

$self->{value} += $self->{increment};
return $self->{value};
}

1;

0 comments on commit a16fb33

Please sign in to comment.