Name
CatalystX::Usul::Encoding - Create additional methods for different encodings
Version
$Revision: 1139 $
Synopsis
use parent qw(CatalystX::Usul::Encoding);
__PACKAGE__->mk_encoding_methods( qw(get_req_array get_req_value) );
sub get_req_array {
my ($self, $req, $field) = @_; my $value = $req->params->{ $field };
$value = defined $value ? $value : [];
return (is_arrayref $value) ? $value : [ $value ];
}
sub get_req_value {
my ($self, $req, $field) = @_; my $value = $req->params->{ $field };
return (is_arrayref $value) ? $value->[ 0 ] : $value;
}
# The standard calls are
$array = $self->get_req_array( $c->req, $field );
$value = $self->get_req_value( $c->req, $field );
# but now we can call these methods also
$array = $self->get_req_array_ascii_encoding( $c->req, $field );
$array = $self->get_req_array_iso_8859_1_encoding( $c->req, $field );
$array = $self->get_req_array_utf_8_encoding( $c->req, $field );
$array = $self->get_req_array_guess_encoding( $c->req, $field );
$value = $self->get_req_value_ascii_encoding( $c->req, $field );
$value = $self->get_req_value_iso_8859_1_encoding( $c->req, $field );
$value = $self->get_req_value_utf_8_encoding( $c->req, $field );
$value = $self->get_req_value_guess_encoding( $c->req, $field );
Description
For each input method defined in your class "mk_encoding_methods" defines additional methods; my_input_method_utf_8_encoding
and my_input_method_guess_encoding
for example
Subroutines/Methods
mk_encoding_methods
Takes a list of method names in the calling package. For each of these a set of new methods are defined in the calling package. The method set is defined by the list of values in the $ENCODINGS
package variable. Each of these newly defined methods calls _decode_data
with a different encoding name
_decode_data
Decodes the data passed using the given encoding name. Can handle both scalars and array refs but not hashes
_guess_encoding
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
_method_name
Takes an encoding name and converts it to a private method name
Diagnostics
None
Configuration and Environment
None
Dependencies
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) 2011 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