OK, here is what I've got (in case anyone is interested):

[% Use myurl = url('/cgi-bin/blah.pl') %]
[% Use Sticky %]
<a href="[% myurl(action="blah1") | 
    sticky('param1','param2') %]">Do Blah</a>

The above makes generates the following (assuming that param1 
and param2 are defined when the page is rendered):
<a href="/cgi-bin/blah.pl?action=blah1&param1=value1&param2=value2">Do Blah</a>

All comments appreciated.  (I don't like how URI.pm's 
'query_from' method uses '&' to separate instead of ';'.)

regards,
Brian

-------------------------------------------------------

package WC::Plugin::Sticky;

use strict;
use CGI;
use URI;

require Template::Plugin::Filter;
use base qw(Template::Plugin::Filter);

use vars qw($DYNAMIC $FILTER_NAME);
$DYNAMIC = 1;
$FILTER_NAME = 'sticky';


sub init {
    my $self = shift;
    my $name = $self->{_ARGS}->[0] || $FILTER_NAME;
    $self->install_filter($name);
   
    return $self;
}

sub filter {
    my($self, $url, $args, $config) = @_;
    $args = $self->merge_args($args);
    my $cgi = CGI->new();
    my $param_hash = $cgi->Vars();
    my %sticky_values = ();
    my @args = @{$args};
    if(scalar(@args) > 0){
        for my $arg (@args){
            $sticky_values{$arg} = $param_hash->{$arg};
        }
    }else{    
        %sticky_values = %{$param_hash};        
    }
    my $u = URI->new($url);
    
    # the next 14 lines or so were copied from 'HTML::StickyQuery'
    my %original;
    my @original = $u->query_form;
    while (my ($key, $val) = splice(@original, 0, 2)){
        if (exists $original{$key}) {
            if (ref $original{$key} eq 'ARRAY') {
                push @{$original{$key}}, $val;
            }else{
                $original{$key} = [ $original{$key}, $val ];
            }
        }else{
            $original{$key} = $val;             
        }
    } 
    my %merged = (%original, %sticky_values);
    $u->query_form(%merged); 
    return $u->as_string();
}


1; 


Reply via email to