[interchange-cvs] interchange - heins modified lib/Vend/Menu.pm

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Sun Aug 18 22:27:00 2002


User:      heins
Date:      2002-08-19 02:26:01 GMT
Modified:  lib/Vend Menu.pm
Log:
* Get rid of chicken-before-egg problem on simple menus -- the indicator
  was difficult to set and read in one pass. Solved by doing a pass on
  the list to do transforms, then feed the results to the menu_link
  routine.

  Custom iterator routines will have to handle this themselves.

Revision  Changes    Path
2.13      +89 -27    interchange/lib/Vend/Menu.pm


rev 2.13, prev_rev 2.12
Index: Menu.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /var/cvs/interchange/lib/Vend/Menu.pm,v
retrieving revision 2.12
retrieving revision 2.13
diff -u -r2.12 -r2.13
--- Menu.pm	18 Aug 2002 08:00:19 -0000	2.12
+++ Menu.pm	19 Aug 2002 02:26:01 -0000	2.13
@@ -1,6 +1,6 @@
 # Vend::Menu - Interchange payment processing routines
 #
-# $Id: Menu.pm,v 2.12 2002/08/18 08:00:19 mheins Exp $
+# $Id: Menu.pm,v 2.13 2002/08/19 02:26:01 mheins Exp $
 #
 # Copyright (C) 2002 Mike Heins, <mike@perusion.net>
 #
@@ -21,7 +21,7 @@
=20
 package Vend::Menu;
=20
-$VERSION =3D substr(q$Revision: 2.12 $, 10);
+$VERSION =3D substr(q$Revision: 2.13 $, 10);
=20
 use Vend::Util;
 use strict;
@@ -98,6 +98,19 @@
 		}
 		return 1;
 	},
+	page_class =3D> sub {
+		my ($row, $fields) =3D @_;
+		return 1 unless $row->{indicated};
+		return 1 if ref($fields) ne 'ARRAY';
+		my $status =3D 1;
+		for(@$fields) {
+			my($f, $c) =3D split /[=3D~]+/, $_;
+			$c ||=3D $f;
+#::logDebug("setting scratch $f to row=3D$c=3D$row->{$c}");
+			$::Scratch->{$f} =3D $row->{$c};
+		}
+		return 1;
+	},
 	menu_group =3D> sub {
 		my ($row, $fields) =3D @_;
 		return 1 if ref($fields) ne 'ARRAY';
@@ -142,6 +155,23 @@
 		}
 		return $status;
 	},
+	indicator_class =3D> sub {
+		my ($row, $fields) =3D @_;
+		return 1 if ref($fields) ne 'ARRAY';
+		for(@$fields) {
+			my ($indicator,$rev, $last, $status);
+			my($s,$r) =3D split /=3D/, $_;
+			$rev =3D $indicator =3D~ s/^\s*!\s*// ? 1 : 0;
+			$last =3D $indicator =3D~ s/\s*!\s*$// ? 1 : 0;
+::logDebug("checking scratch $s=3D$::Scratch->{$s} eq row=3D$r=3D$row->{$r=
}");
+			$status =3D $::Scratch->{$s} eq $row->{$r};
+			if($rev xor $status) {
+				$row->{indicated} =3D 1;
+			}
+			last if $last;
+		}
+		return 1;
+	},
 	indicator_profile =3D> sub {
 		my ($row, $fields) =3D @_;
 		return 1 if ref($fields) ne 'ARRAY';
@@ -156,9 +186,15 @@
 				next unless $last;
 			}
 			last if $last;
-			$status =3D $Global::Variable->{MV_PAGE} eq $indicator;
-			($row->{indicated} =3D 1, next)
-				if $rev xor $status;
+		}
+		return 1;
+	},
+	indicator_page =3D> sub {
+		my ($row, $fields) =3D @_;
+		return 1 if ref($fields) ne 'ARRAY';
+		for(@$fields) {
+			($row->{indicated} =3D 1, last)
+				if $Global::Variable->{MV_PAGE} eq $row->{$_};
 		}
 		return 1;
 	},
@@ -170,28 +206,20 @@
 			next unless $indicator =3D $row->{$_};
 			$rev =3D $indicator =3D~ s/^\s*!\s*// ? 1 : 0;
 			$last =3D $indicator =3D~ s/\s*!\s*$// ? 1 : 0;
-			if($indicator =3D~ /^\s*([-\w.:]+)\s*$/) {
+			if($indicator =3D~ /^\s*([-\w.:][-\w.:]+)\s*$/) {
 				$status =3D  $CGI::values{$1};
-#::logDebug("variable thing $indicator($1)") if  $row->{debug};
 			}
 			elsif ($indicator =3D~ /^\s*`(.*)`\s*$/s) {
-#::logDebug("calc thing $1") if  $row->{debug};
 				$status =3D Vend::Interpolate::tag_calc($1);
 			}
 			elsif ($indicator =3D~ /\[/s) {
-#::logDebug("ITL thing") if  $row->{debug};
 				$status =3D interpolate_html($indicator);
 				$status =3D~ s/\s+//g;
 			}
-#::logDebug("indicator status=3D$status rev=3D$rev last=3D$last") if  $row=
->{debug};
 			if($rev xor $status) {
 				$row->{indicated} =3D 1;
-				next unless $last;
 			}
 			last if $last;
-			$status =3D $Global::Variable->{MV_PAGE} eq $indicator;
-			($row->{indicated} =3D 1, next)
-				if $rev xor $status;
 		}
 		return 1;
 	},
@@ -279,16 +307,7 @@
 	my @out;
 	my $u;
=20
-	my $header;
-	$header =3D ::interpolate_html($opt->{header_template})
-		if $opt->{header_template};
-	if($header =3D~ /\S/) {
-		$header =3D Vend::Tags->uc_attr_list($opt, $header);
-		push @out, $header;
-	}
-
 	my %defaults =3D (
-				iterator    =3D> \&menu_link,
 				head_skip   =3D> 1,
 			);
=20
@@ -296,14 +315,40 @@
 		next if defined $opt->{$k};
 		$opt->{$k} =3D $v;
 	}
-	push @out, Vend::Tags->loop(undef,$opt,$template);
+
+	my $iterator;
+
+	my $main;
+	if($opt->{iterator}) {
+		$main =3D Vend::Tags->loop(undef,$opt,$template);
+	}
+	else {
+		$opt->{iterator} =3D \&transforms_only;
+		delete $opt->{_transforms};
+		Vend::Tags->loop(undef,$opt,'');
+		my $list =3D $opt->{object}{mv_results};
+		$main =3D '';
+		for(@$list) {
+::logDebug("here's a row: " . ::uneval($_));
+			$main .=3D menu_link($template, $_, $opt);
+		}
+	}
+
+	my $header;
+	$header =3D ::interpolate_html($opt->{header_template})
+		if $opt->{header_template};
+	if($header =3D~ /\S/) {
+		push @out, Vend::Tags->uc_attr_list($opt, $header);
+	}
+
+	push @out, $main;
=20
 	my $footer;
+
 	$footer =3D ::interpolate_html($opt->{footer_template})
 		if $opt->{footer_template};
 	if($footer =3D~ /\S/) {
-		$footer =3D Vend::Tags->uc_attr_list($opt, $footer);
-		push @out, $footer;
+		push @out, Vend::Tags->uc_attr_list($opt, $footer);
 	}
=20
 	return join "\n", @out;
@@ -993,6 +1038,23 @@
 	return join "\n", @out, '';
 }
=20
+sub transforms_only {
+	my ($template, $row, $opt) =3D @_;
+
+	my %line;
+	if(ref($row) eq 'ARRAY') {
+		$opt->{_fa} ||=3D $opt->{object}{mv_field_names};
+		@line{@{$opt->{_fa}}} =3D @$row;
+		$row =3D \%line;
+	}
+
+	for(@{$opt->{_transform}}) {
+		return unless $transform{$_}->($row, $opt->{$_});
+	}
+	return;
+}
+
+
 sub menu_link {
 	my ($template, $row, $opt) =3D @_;
=20
@@ -1065,7 +1127,7 @@
 	}
=20
 	my @transform;
-	my @ordered_transform =3D qw/localize entities nbsp/;
+	my @ordered_transform =3D qw/page_class indicator_class localize entities=
 nbsp/;
 	my %ordered;
 	@ordered{@ordered_transform} =3D @ordered_transform;
=20