Apache2-API
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Apache2/API/Query.pm view on Meta::CPAN
{
my @values;
if( !ref( $value ) )
{
@values = split( "\0", $value );
}
elsif( ref( $value ) eq 'ARRAY' )
{
@values = @$value;
}
else
{
die( "Invalid value found: $value. Not string or arrayref!" );
}
# push @{$self->{qq}->{$key_unesc}}, map { uri_unescape($_) } @values;
for( @values )
{
$_ = URI::Escape::uri_unescape( $_ );
$_ = Encode::decode_utf8( $_ ) if( !utf8::is_utf8( $_ ) );
push( @{$self->{qq}->{$key_unesc}}, $_ );
}
}
}
}
sub FREEZE
{
my $self = CORE::shift( @_ );
my $serialiser = CORE::shift( @_ ) // '';
my $class = CORE::ref( $self );
my %hash = %$self;
# Return an array reference rather than a list so this works with Sereal and CBOR
# On or before Sereal version 4.023, Sereal did not support multiple values returned
CORE::return( [$class, \%hash] ) if( $serialiser eq 'Sereal' && Sereal::Encoder->VERSION <= version->parse( '4.023' ) );
# But Storable want a list with the first element being the serialised element
CORE::return( $class, \%hash );
}
sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
sub THAW
{
my( $self, undef, @args ) = @_;
my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
my $new;
# Storable pattern requires to modify the object it created rather than returning a new one
if( CORE::ref( $self ) )
{
foreach( CORE::keys( %$hash ) )
{
$self->{ $_ } = CORE::delete( $hash->{ $_ } );
}
$new = $self;
}
else
{
$new = bless( $hash => $class );
}
CORE::return( $new );
}
1;
# NOTE: POD
__END__
=encoding utf8
=head1 NAME
Apache2::API::Query - utf8 compliant URI query string manipulation
=head1 SYNOPSIS
# Constructor - using a GET query string
$qq = Apache2::API::Query->new($query_string);
# OR Constructor - using a hashref of key => value parameters
$qq = Apache2::API::Query->new($cgi->Vars);
# OR Constructor - using an array of successive keys and values
$qq = Apache2::API::Query->new(@params);
# Clone the current object
$qq2 = $qq->clone;
# Revert back to the initial constructor state (to do it all again)
$qq->revert;
# Remove all occurrences of the given parameters
$qq->strip('page', 'next');
# Remove all parameters except the given ones
$qq->strip_except('pagesize', 'order');
# Remove all empty/undefined parameters
$qq->strip_null;
# Replace all occurrences of the given parameters
$qq->replace(page => $page, foo => 'bar');
# Set the argument separator to use for output (default: unescaped '&')
$qq->separator(';');
# Output the current query string
print "$qq"; # OR $qq->stringify;
# Stringify with explicit argument separator
$qq->stringify(';');
# Output the current query string with a leading '?'
$qq->qstringify;
# Stringify with a leading '?' and an explicit argument separator
$qq->qstringify(';');
# Get a flattened hash/hashref of the current parameters
# (single item parameters as scalars, multiples as an arrayref)
my %qq = $qq->hash;
# Get a non-flattened hash/hashref of the current parameters
# (parameter => arrayref of values)
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.413 second using v1.00-cache-2.02-grep-82fe00e-cpan-9e6bc14194b )