[wellwell-devel] [wellwell/zoom] Add WellWell::Zoom::Increment class.

Stefan Hornburg wellwell-devel at rt.icdevgroup.org
Mon Sep 6 12:18:02 UTC 2010


commit a16fb3361053052789fd51b4a7dff79c4c4dda00
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Mon Sep 6 10:47:32 2010 +0200

    Add WellWell::Zoom::Increment class.

 lib/WellWell/Zoom.pm           |   22 +++++++++++++
 lib/WellWell/Zoom/Increment.pm |   67 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 0 deletions(-)
---
diff --git a/lib/WellWell/Zoom.pm b/lib/WellWell/Zoom.pm
index ea02a12..f36ce46 100644
--- a/lib/WellWell/Zoom.pm
+++ b/lib/WellWell/Zoom.pm
@@ -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;
@@ -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);
 				}
@@ -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
@@ -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;
diff --git a/lib/WellWell/Zoom/Increment.pm b/lib/WellWell/Zoom/Increment.pm
new file mode 100644
index 0000000..7fe7749
--- /dev/null
+++ b/lib/WellWell/Zoom/Increment.pm
@@ -0,0 +1,67 @@
+# WellWell::Zoom::Increment - WellWell increment objects
+#
+# Copyright (C) 2010 Stefan Hornburg (Racke) <racke at 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;
+



More information about the wellwell-devel mailing list