Name

CatalystX::Usul::QueryRequest - Create request query methods for different encodings

Version

Describes v0.16.$Rev: 1 $

Synopsis

use  qw(CatalystX::Usul::QueryRequest);

Description

Creates a pair of methods (one for scalar values and one for array refs) for each of the encodings specified in the encodings attribute

Configuration and Environment

Defines the following accessors:

encoding

An encoding type which is required

encodings

Array ref which defaults to [ qw(ascii iso-8859-1 UTF-8 guess) ]

request

A weakened request object reference. This is a writable attribute

scrubbing

Boolean used by "query_array" and "query_value" to determine if input value should be cleaned of potentially dangerous characters

scrubber

List of characters to scrub from input values. Defaults to '"/\;. Can also be a coderef in which case it is called with the input value and it's return value is used

Subroutines/Methods

BUILD

Create the request query methods

query_array

$array_ref = $self->query_array( $attr );

Uses the encoding attribute to generate the method call to decode the input values. Will try to guess the encoding if one is not provided

If the form attribute _${attr}_nrows is not defined then this method returns an array ref of the the form attributes. If the _${attr}_nrows is defined then this method returns an array ref of selected values from the select checkbox column of the table widget

query_hash

$hash_ref = $self->query_hash( $attr, \@fields );

Returns a hash ref of data extracted from the table embeded in a form

query_value

$scalar_value = $self->query_value( $attr );

Returns the requested parameter in a scalar context. Uses encoding attribute to generate the method call to decode the input value. Will try to guess the encoding if one is not provided

query_value_by_fields

$hash_ref = $self->query_value_by_fields( @fields );

Returns a hash_ref of fields and their values if the values are defined by the request. Calls "query_value" for each of supplied fields

_decode_data

$array_ref = $self->_decode_data( $encoding, $array_ref );
$value     = $self->_decode_data( $encoding, $value     );

Decodes the data passed using the given encoding name. Can handle both scalars and array refs but not hashes

_get_req_array

$array_ref = $self->_get_req_array( $attr );

Uses the request attribute that must implement a params method which returns a hash ref. The method returns the value for $attr from that hash. This method will always return a array ref

_get_req_value

$value = $self->_get_req_value( $attr );

Uses the request attribute that must implement a params method which returns a hash ref. The method returns the value for $attr from that hash. This method will always return a scalar

_guess_encoding

$value = $self->_guess_encoding( $req_method, $attr );

If you really don't know what the source encoding is then this method will use Encode::Guess to determine the encoding. If successful calls "_decode_data" to get the job done

_scrub

$value = $self->_scrub( $value );

Removes the $self->scrubbing from the value

__method_name

$name = __method_name( $encoding );

Takes an encoding name and converts it to a private method name

Diagnostics

None

Dependencies

CatalystX::Usul::Moose
Encode
Encode::Guess

Incompatibilities

There are no known incompatibilities in this module

Bugs and Limitations

There are no known bugs in this module. Please report problems to the address below. Patches are welcome

Author

Peter Flanigan, <Support at RoxSoft.co.uk>

License and Copyright

Copyright (c) 2014 Peter Flanigan. All rights reserved

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic

This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE