Skip to content

Commit

Permalink
Move ncheck subroutine to global
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
Josh Lavin committed Sep 25, 2015
1 parent ad74d41 commit f1dde34
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 75 deletions.
75 changes: 0 additions & 75 deletions dist/strap/catalog.cfg
Expand Up @@ -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=
Expand Down
77 changes: 77 additions & 0 deletions 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

0 comments on commit f1dde34

Please sign in to comment.