⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryparam.pm

📁 1. 记录每个帖子的访问人情况
💻 PM
字号:
package URI::_query;  # we fill methods into this namespace stilluse strict;sub query_param {    my $self = shift;    my @old = $self->query_form;    if (@_ == 0) {	# get keys	my %seen;	my @keys;	for (my $i = 0; $i < @old; $i += 2) {	    push(@keys, $old[$i]) unless $seen{$old[$i]}++;	}	return @keys;    }    my $key = shift;    my @i;    for (my $i = 0; $i < @old; $i += 2) {	push(@i, $i) if $old[$i] eq $key;    }    if (@_) {	my @new = @old;	my @new_i = @i;	my @vals = map { ref($_) eq 'ARRAY' ? @$_ : $_ } @_;	#print "VALS:@vals [@i]\n";	while (@new_i > @vals) {	    #print "REMOVE $new_i[-1]\n";	    splice(@new, pop(@new_i), 2);	}	while (@vals > @new_i) {	    my $i = @new_i ? $new_i[-1] + 2 : @new;	    #print "SPLICE $i\n";	    splice(@new, $i, 0, $key => pop(@vals));	}	for (@vals) {	    #print "SET $new_i[0]\n";	    $new[shift(@new_i)+1] = $_;	}	$self->query_form(@new);    }    return wantarray ? @old[map $_+1, @i] : @i ? $old[$i[0]+1] : undef;}sub query_param_append {    my $self = shift;    my $key = shift;    $self->query_form($self->query_form, $key => \@_);  # XXX    return;}sub query_param_delete {    my $self = shift;    my $key = shift;    my @old = $self->query_form;    my @vals;    for (my $i = @old - 2; $i >= 0; $i -= 2) {	next if $old[$i] ne $key;	push(@vals, (splice(@old, $i, 2))[1]);    }    $self->query_form(@old) if @vals;    return wantarray ? reverse @vals : $vals[-1];}sub query_form_hash {    my $self = shift;    my @old = $self->query_form;    if (@_) {	$self->query_form(@_ == 1 ? %{shift(@_)} : @_);    }    my %hash;    while (my($k, $v) = splice(@old, 0, 2)) {	if (exists $hash{$k}) {	    for ($hash{$k}) {		$_ = [$_] unless ref($_) eq "ARRAY";		push(@$_, $v);	    }	}	else {	    $hash{$k} = $v;	}    }    return \%hash;}1;__END__=head1 NAMEURI::QueryParam - Additional query methods for URIs=head1 SYNOPSIS  use URI;  use URI::QueryParam;  $u = URI->new("", "http");  $u->query_param(foo => 1, 2, 3);  print $u->query;    # prints foo=1&foo=2&foo=3  for my $key ($u->query_param) {      print "$key: ", join(", ", $u->query_param($key)), "\n";  }=head1 DESCRIPTIONLoading the C<URI::QueryParam> module will add some extra methods toURIs that support query methods.  These methods provide an alternativeinterface to the $u->query_form data.The provided query_param_* methods on pupose made identical to theinterface of the corresponding C<CGI.pm> methods.The following additional methods are made available:=over=item @keys = $u->query_param=item @values = $u->query_param( $key )=item $first_value = $u->query_param( $key )=item $u->query_param( $key, $value,... )If $u->query_param is called with no argments it returns all thedistinct parameter keys of the URI.  In scalar context it returns thenumber of distinct keys.When a $key argument is given it returns the parameter values with thegiven key.  In scalar context only the first parameter value isreturned.If additional arguments are given they are used to update successiveparameters with the given key.  If any of the values provided arearray references then the array is dereferenced to get the actualvalues.=item $u->query_param_append($key, $value,...)The $u->query_param_append method adds new parameters with the givenkey without touching any old parameters with the same key.  Itcan be explained as a more efficient version of:   $u->query_param($key,                   $u->query_param($key),                   $value,...);One difference is that this expression would return the old valuesof $key, while the query_param_append() method will not.=item @values = $u->query_param_delete($key)=item $first_value = $u->query_param_delete($key)This method will delete all key/value pairs with the given key.The old values are returned.  In scalar context only the first valueis returned.Using the query_param_delete() method is slightly more efficient thanthe equivalent:   $u->query_param($key, []);=item $hashref = $u->query_form_hash=item $u->query_form_hash( \%new_form )This method will return a reference to a hash that represents thequery form's key/value pairs.  If a key occurs multiple times, then the hashvalue will become an array reference.Note that sequence information is lost.  It means that:   $u->query_form_hash($u->query_form_hash)is not necessarily a no-op as it might reorder the key/value pairs.The values returned by the query_param() method should stay the samethough.=back=head1 SEE ALSOL<URI>, L<CGI>=head1 COPYRIGHTCopyright 2002 Gisle Aas.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -