Skip to content

Instantly share code, notes, and snippets.

@brianjmiller
Created March 7, 2011 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianjmiller/858523 to your computer and use it in GitHub Desktop.
Save brianjmiller/858523 to your computer and use it in GitHub Desktop.
[delayed_query] tag for Interchange
UserTag delayed_query Order list
UserTag delayed_query addAttr
UserTag delayed_query attrAlias args list
UserTag delayed_query attrAlias arg list
UserTag delayed_query hasEndTag
UserTag delayed_query PosNumber 1
UserTag delayed_query Routine <<EOF
sub {
# This function operates as a wrapper for the [loop] coretag; the loop tag doesn't work very
# well with the scan/more-list functionality if the list it has is the formatted output of the
# query tag (with the wantarray flag specified). The list always overrides the search object
# within the loop code, as the list is checked and processed first.
my ($list, $opt, $text) = @_;
if ($opt->{more} and $Vend::More_in_progress and $::Instance->{SearchObject}{''}) {
# The scan actionmap was used in preparation of this page; therefore
# override whatever list is passed in.
$opt->{object} = $::Instance->{SearchObject}{''};
return region($opt, $text);
}
if (ref $opt->{data} eq 'ARRAY') {
# This lets us pass an arrayref constructed from the query tag to the data argument,
# and we break it up so it will work with the loop tag.
# To build the data object:
# @result = $Tag->query({ sql => '<SOME SQL>', wantarray => 1});
# $Tag->delayed_query( { data => \@result } );
# @result will have ( @records, %field_name_to_indexes, @field_names ).
@{$opt->{object}}{qw( mv_results mv_field_hash mv_field_names )} = @{$opt->{data}};
}
return Vend::Interpolate::tag_loop_list( $list, $opt, $text );
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment