[interchange] Move ncheck subroutine to global

Josh Lavin interchange-cvs at icdevgroup.org
Sat Sep 26 00:06:03 UTC 2015


commit f1dde3448fe3a4b20238a9b79f67825347719f7a
Author: Josh Lavin <jlavin at endpoint.com>
Date:   Fri Sep 25 15:00:16 2015 -0700

    Move ncheck subroutine to global
    
    Various installations had trouble with $Tag being called from a non-global sub.
    Including: Perl 5.14.1 and 5.22.0.
    However, a different 5.14.1 installation worked...

 dist/strap/catalog.cfg                |   75 --------------------------------
 dist/strap/config/ncheck_category.tag |   77 +++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 75 deletions(-)
---
diff --git a/dist/strap/catalog.cfg b/dist/strap/catalog.cfg
index 994416f..576267f 100644
--- a/dist/strap/catalog.cfg
+++ b/dist/strap/catalog.cfg
@@ -710,81 +710,6 @@ EOR
 ## Map a subroutine to happen if the page is not there
 SpecialSub  missing  ncheck_category
 
-## Subroutine that looks for a prod_group and category in
-## a missing page and delivers them
-Sub ncheck_category <<EOS
-sub {
-	my ($name) = @_;
-	return unless $name =~ m{^[A-Z]};
-	my $results_page = $Config->{'SpecialPage'}{'results'} || 'results';
-	
-	my $xmoz = $Tag->env('HTTP_X_MOZ') || '';
-	if($xmoz eq 'prefetch') {
-		## fail to deliver page if Firefox is prefetching, as they will send 2nd request and mess up paging
-		return $Tag->deliver({ location => $Tag->area('prefetch-not-allowed'), type => 'text/html' });
-	}
-
-	my ($prod_group, $category, $page) = split m{/}, $name; 
-	my $a_prod_group = $prod_group;
-	my $a_category = $category;
-	for($prod_group, $category) {
-		s,-, ,g;
-		s,_,-,g;
-		s,::,/,g;
-	}
-	my ($search, $o);
-	my $limit = $Values->{mv_matchlimit} || $Variable->{MV_DEFAULT_MATCHLIMIT} || 50;
-	my $more_link = $a_prod_group;
-	if($category && $category !~ /^([0-9]+|Next|Previous)$/ ) {
-		$more_link .= '/' . $a_category;
-	}
-	else {
-		$page = $category;
-		$category = undef;
-	}
-#Debug("prod_group = $prod_group, category = $category, page = $page");
-
-	if($page) {
-		my $first_match = $Values->{mv_first_match} || 0;
-#Debug("first_match starts with = $first_match");
-		if($page =~ /[0-9]+/) { $first_match = (($page - 1) * $limit) + 1; }
-		elsif($page eq 'Next') { $first_match += $limit unless $Scratch->{did_order}; }
-		elsif($page eq 'Previous') { $first_match -= $limit unless $Scratch->{did_order}; }
-		else { $first_match = 0; }
-		$search->{fm} = $first_match > 0 ? $first_match : 0;
-#Debug("first_match = $first_match, limit = $limit");
-	}
-	else {
-		$search->{fm} = 0;
-	}
-
-	if($a_prod_group eq 'All-Products') {
-		$search->{ra} = 1;
-		$search->{tf} = [ 'category', 'description' ];
-	}
-	else {
-		$search->{co} = 1;
-		$search->{sf} = [ 'prod_group', 'category' ];
-		$search->{op} = [ 'eq', 'eq' ];
-		$search->{se} = [ $prod_group, $category ];
-		$search->{tf} = [ 'prod_group', 'category', 'description' ];
-	}
-	$search->{sp} = $results_page;
-	$search->{fi} = 'products';
-	$search->{st} = 'db';
-	$search->{ml} = $limit;
-	$search->{va} = "more_link=$more_link";
-	$search->{mv_todo} = 'search';
-#Debug("search is: " . $Tag->uneval({ ref => $search }) );
-	$Tag->search({ search => $search });
-	if (($o = $Search->{''}) && @{$o->{mv_results}}) {
-		return (1,  $search->{sp});
-	}
-
-	return;
-}
-EOS
-
 UserTag edisplay Alias error auto=1 class="alert alert-danger list-unstyled"
 UserTag wdisplay Alias warnings auto=1 list_class="alert alert-success list-unstyled"
 UserTag ecgi     Alias cgi keep=1 filter=encode_entities name=
diff --git a/dist/strap/config/ncheck_category.tag b/dist/strap/config/ncheck_category.tag
new file mode 100644
index 0000000..f8738ef
--- /dev/null
+++ b/dist/strap/config/ncheck_category.tag
@@ -0,0 +1,77 @@
+Message ncheck
+GlobalSub <<EOS
+sub ncheck_category {
+	##
+	## Subroutine that looks for a prod_group and category in
+	## a missing page and delivers them
+	##
+	my ($name) = @_;
+	return unless $name =~ m{^[A-Z]};
+	my $results_page = $Vend::Cfg->{'SpecialPage'}{'results'} || 'results';
+	
+	my $xmoz = Vend::Tags->env('HTTP_X_MOZ') || '';
+	if($xmoz eq 'prefetch') {
+		## fail to deliver page if Firefox is prefetching, as they will send 2nd request and mess up paging
+		return Vend::Tags->deliver({ location => Vend::Tags->area('prefetch-not-allowed'), type => 'text/html' });
+	}
+
+	my ($prod_group, $category, $page) = split m{/}, $name; 
+	my $a_prod_group = $prod_group;
+	my $a_category = $category;
+	for($prod_group, $category) {
+		s,-, ,g;
+		s,_,-,g;
+		s,::,/,g;
+	}
+	my ($search, $o);
+	my $limit = $::Values->{mv_matchlimit} || $::Variable->{MV_DEFAULT_MATCHLIMIT} || 50;
+	my $more_link = $a_prod_group;
+	if($category && $category !~ /^([0-9]+|Next|Previous)$/ ) {
+		$more_link .= '/' . $a_category;
+	}
+	else {
+		$page = $category;
+		$category = undef;
+	}
+#::logDebug("prod_group = $prod_group, category = $category, page = $page");
+
+	if($page) {
+		my $first_match = $::Values->{mv_first_match} || 0;
+#::logDebug("first_match starts with = $first_match");
+		if($page =~ /[0-9]+/) { $first_match = (($page - 1) * $limit) + 1; }
+		elsif($page eq 'Next') { $first_match += $limit unless $::Scratch->{did_order}; }
+		elsif($page eq 'Previous') { $first_match -= $limit unless $::Scratch->{did_order}; }
+		else { $first_match = 0; }
+		$search->{fm} = $first_match > 0 ? $first_match : 0;
+#::logDebug("first_match = $first_match, limit = $limit");
+	}
+	else {
+		$search->{fm} = 0;
+	}
+
+	if($a_prod_group eq 'All-Products') {
+		$search->{ra} = 1;
+		$search->{tf} = [ 'category', 'description' ];
+	}
+	else {
+		$search->{co} = 1;
+		$search->{sf} = [ 'prod_group', 'category' ];
+		$search->{op} = [ 'eq', 'eq' ];
+		$search->{se} = [ $prod_group, $category ];
+		$search->{tf} = [ 'prod_group', 'category', 'description' ];
+	}
+	$search->{sp} = $results_page;
+	$search->{fi} = 'products';
+	$search->{st} = 'db';
+	$search->{ml} = $limit;
+	$search->{va} = "more_link=$more_link";
+	$search->{mv_todo} = 'search';
+#::logDebug("search is: " . Vend::Tags->uneval({ ref => $search }) );
+	Vend::Tags->search({ search => $search });
+	if (($o = $::Instance->{SearchObject}->{''}) && @{$o->{mv_results}}) {
+		return (1,  $search->{sp});
+	}
+
+	return;
+}
+EOS



More information about the interchange-cvs mailing list