view release on metacpan or search on metacpan
lib/Data/Recursive/Encode.pm view on Meta::CPAN
=item decode
my $ret = Data::Recursive::Encode->decode($encoding, $data, [CHECK]);
Returns a structure containing nodes which are decoded from the specified
encoding.
=item encode
my $ret = Data::Recursive::Encode->encode($encoding, $data, [CHECK]);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Riak/Result/JSONValue.pm view on Meta::CPAN
version 2.0
=head1 DESCRIPTION
Results for requests resulting in JSON data use this role to provide convenient
access to the decoded body payload.
=head1 METHODS
=head2 json_value
view all matches for this distribution
view release on metacpan or search on metacpan
xt/fork_bomb.t view on Meta::CPAN
# Sample the latest: should be some valid combination
my $v = $r->latest(0);
ok defined $v, 'latest() succeeds after storm';
my $w_enc = int($v / 100_000);
my $i_enc = $v % 100_000;
cmp_ok $w_enc, '>=', 1, "decoded writer $w_enc in range";
cmp_ok $w_enc, '<=', $N, "decoded writer in range";
cmp_ok $i_enc, '>=', 1, "decoded iter in range";
cmp_ok $i_enc, '<=', $PER, "decoded iter in range";
done_testing;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Sah/Filter/perl/Str/try_decode_json.pm view on Meta::CPAN
my $res = {};
$res->{modules}{"JSON::PP"} //= 0;
$res->{expr_filter} = join(
"",
"do { my \$decoded; eval { \$decoded = JSON::PP->new->allow_nonref->decode($dt); 1 }; \$@ ? $dt : \$decoded }",
);
$res;
}
lib/Data/Sah/Filter/perl/Str/try_decode_json.pm view on Meta::CPAN
This rule is sometimes convenient if you want to accept unquoted string or a
data structure (encoded in JSON). This means, compared to just decoding from
JSON, you don't have to always quote your string. But beware of traps like the
bare values C<null>, C<true>, C<false> becoming undef/1/0 in Perl instead of
string literals, because they can be JSON-decoded.
=for Pod::Coverage ^(meta|filter)$
=head1 HOMEPAGE
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Section/Simple.pm view on Meta::CPAN
=head2 utf8 pragma
If you enable L<utf8> pragma in the caller's package (or the package
you're inspecting with the OO interface), the data retrieved via
C<get_data_section> is decoded, but otherwise undecoded. There's no
reliable way for this module to programmatically know whether utf8
pragma is enabled or not: it's your responsibility to handle them
correctly.
=head1 AUTHOR
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Section.pm view on Meta::CPAN
Carp::confess("bogus data section: text outside of named section")
unless defined $current;
$current_line++;
unless ($default_encoding eq 'bytes') {
my $decoded_line = eval { decode($default_encoding, $line, Encode::FB_CROAK) }
or warn "Invalid character encoding in $current, line $current_line\n";
$line = $decoded_line if defined $decoded_line;
}
$line =~ s/\A\\//;
${$template->{$current}} .= $line;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Serializer/Cookbook.pm view on Meta::CPAN
my $raw_serializer = Data::Serializer::Raw->new();
=head1 Encrypting your data
You wish to encrypt your data structure, so that it can only be decoded
by someone who shares the same key.
=head2 Solution
$serializer->secret('mysecret');
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/SimpleKV.pm view on Meta::CPAN
to call save() will overwrite previous changes.
=head1 UTF-8 SUPPORT
The module fully supports UTF-8 encoded strings for both keys and values.
All string data is properly encoded/decoded to ensure correct storage
and retrieval of international characters.
=head1 DEPENDENCIES
=over 4
view all matches for this distribution
view release on metacpan or search on metacpan
t/integration/06_options.t view on Meta::CPAN
use File::Temp qw(tempdir);
my $huge = '1267650600228229401496703205376'; # 2**100
my $smile = "\x3A\x29\x0A\x03\x26\x8D\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
my $decoded_default = decode_smile($smile);
ok(ref($decoded_default), 'default decode uses an object for huge integer');
is($decoded_default->bstr, $huge, 'default decode uses Math::BigInt value');
my $decoded_native = decode_smile($smile, { use_bigint => 0 });
ok(!ref($decoded_native), 'decode with use_bigint=0 returns native scalar');
like("$decoded_native", qr/1\.26765060022823e\+30|1267650600228229401496703205376/, 'decode with use_bigint=0 returns numeric approximation');
my $encoded = encode_smile({ a => 1 }, {});
ok(length($encoded) > 4, 'encode_smile accepts empty options hashref');
my $encoded_no_header = encode_smile({ a => 1 }, { write_header => 0 });
ok(substr($encoded_no_header, 0, 3) ne "\x3A\x29\x0A", 'encode_smile can omit header');
is(decode_smile($encoded_no_header), { a => 1 }, 'decode_smile decodes headerless payload by default');
my $encoded_no_shared_values = encode_smile({ a => 'same', b => 'same' }, { shared_values => 0 });
my $decoded_no_shared_values = decode_smile($encoded_no_shared_values);
is($decoded_no_shared_values, { a => 'same', b => 'same' }, 'encode_smile supports shared_values option');
my $dir = tempdir(CLEANUP => 1);
my $file = "$dir/opts.sml";
ok(dump_smile($file, { x => 1 }, { write_header => 0 }), 'dump_smile passes encode options');
is(load_smile($file, {}), { x => 1 }, 'load_smile accepts options hashref');
view all matches for this distribution
view release on metacpan or search on metacpan
t/integration/06_options.t view on Meta::CPAN
use File::Temp qw(tempdir);
my $huge = '1267650600228229401496703205376'; # 2**100
my $smile = "\x3A\x29\x0A\x03\x26\x8D\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
my $decoded_default = decode_smile($smile);
ok(ref($decoded_default), 'default decode uses an object for huge integer');
is($decoded_default->bstr, $huge, 'default decode uses Math::BigInt value');
my $decoded_native = decode_smile($smile, { use_bigint => 0 });
ok(!ref($decoded_native), 'decode with use_bigint=0 returns native scalar');
like("$decoded_native", qr/1\.26765060022823e\+30|1267650600228229401496703205376/, 'decode with use_bigint=0 returns numeric approximation');
my $nested_smile = "\x3A\x29\x0A\x03\xF8\x26\x8D\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xF9";
my $nested_default = decode_smile( $nested_smile );
ok( ref( $nested_default->[0] ), 'default decode keeps nested huge integer as object' );
t/integration/06_options.t view on Meta::CPAN
my $encoded_no_header = encode_smile({ a => 1 }, { write_header => 0 });
ok(substr($encoded_no_header, 0, 3) ne "\x3A\x29\x0A", 'encode_smile can omit header');
is(decode_smile($encoded_no_header), { a => 1 }, 'decode_smile decodes headerless payload by default');
my $encoded_no_shared_values = encode_smile({ a => 'same', b => 'same' }, { shared_values => 0 });
my $decoded_no_shared_values = decode_smile($encoded_no_shared_values);
is($decoded_no_shared_values, { a => 'same', b => 'same' }, 'encode_smile supports shared_values option');
my $dir = tempdir(CLEANUP => 1);
my $file = "$dir/opts.sml";
ok(dump_smile($file, { x => 1 }, { write_header => 0 }), 'dump_smile passes encode options');
is(load_smile($file, {}), { x => 1 }, 'load_smile accepts options hashref');
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/SortedSet/Shared/Strings.pm view on Meta::CPAN
A string-keyed sorted set in shared memory: the same API as
L<Data::SortedSet::Shared> but with B<string members> instead of int64 ids. It is
a thin layer composing two shared structures -- a L<Data::SortedSet::Shared> for
the (id, score) ordering and a L<Data::Intern::Shared> mapping each string key to
a dense id. Keys are interned on the way in and decoded back to strings on the way
out.
Because both backing stores live in shared memory, the set works B<across
processes>: every process resolves a key to the same id, so a string-keyed
leaderboard, priority queue, or rate limiter can be shared by many workers.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Structure/Deserialize/Auto.pm view on Meta::CPAN
$n = shift(@decoders);
my $decoder = $decoders{$n};
try {
my $structure = $decoder->($v);
if (ref($structure) eq 'HASH' || ref($structure) eq 'ARRAY') {
# warn("decoded using '$n'");
return $decoder->($v);
}
} catch {
# ignore any errors and try the next decoder, or die out at the bottom
};
view all matches for this distribution
view release on metacpan or search on metacpan
ok( has_utf8( $hash2 ), "Has utf8" );
is( has_utf8( $hash2 ), $hash2, "Has utf8" );
is( $hash2->{key1}, $hash->{key1}, "Same string" );
ok( !compare( $hash2->{key1}, $hash->{key1} ), "Different encoding" );
ok( utf8_off( $hash2 ), "Have decoded utf8" );
ok( !has_utf8( $hash2 ), "Has not utf8" );
is( $hash2->{key1}, $hash->{key1}, "Same string" );
ok( compare( $hash2->{key1}, $hash->{key1} ), "Same encoding" );
ok( utf8_on( $hash ), "Have encoded utf8" );
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/TOON.pm view on Meta::CPAN
# Output:
# active: true
# age: 30
# name: Alice
my $decoded = Data::TOON->decode($toon);
# Tabular arrays
my $users = {
users => [
{ id => 1, name => 'Alice', role => 'admin' },
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/TagDB/Tag.pm view on Meta::CPAN
=head2 displaycolour
my $displaycolour = $tag->displaycolour( [ %opts ] );
Returns a colour that can be used to display the tag.
This will return a decoded object, most likely (but not necessarily) an instance of L<Data::URIID::Colour>.
Later versions of this module may allow to force a specific type.
This method C<die>s if no value can be found and no L</default> is given (since v0.11).
The following universal options are supported: L</default>.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Transform/ExplicitMetadata.pm view on Meta::CPAN
descriptor number and open mode. It will first try fcntl() with F_GETFL
to determine the open mode, falling back to using FileHandle::Fmode if it's
available. Finally, it will first try re-opening the file descriptor in
read mode, then write mode.
Coderefs cannot be decoded properly. They are recreated by returning a
reference to a dummy sub that returns a message explaning the situation.
=back
=head1 SEE ALSO
view all matches for this distribution
view release on metacpan or search on metacpan
t/01_zlib.t view on Meta::CPAN
my $compressed = $filter->put( [ $teststring, Data::Transform::Meta::EOF->new() ] );
is (@$compressed, 3, "sending a string plus EOF gets the right amount of packets");
pop @$compressed; # the EOF packet doesn't go over the wire normally
my $answer = $filter->get( $compressed );
is( @$answer, 1, 'decoding those gets the correct number of packets');
is( $answer->[0], $teststring, 'the decoded string equals the original' );
}
my $stack = Data::Transform::Stackable->new( Filters =>
[
view all matches for this distribution
view release on metacpan or search on metacpan
t/json_read.t view on Meta::CPAN
use PointReadHandler;
use Test::More;
use Data::Transit;
# scalars
is_decoded_to('["~#\'",null]', undef);
is_decoded_to('["~#\'","foo"]', "foo");
is_decoded_to('["~#\'",1]', 1);
# arrays
is_decoded_to('[]', []);
is_decoded_to('["foo"]', ["foo"]);
# maps
is_decoded_to('["^ "]', {});
is_decoded_to('[["^ "]]', [{}]);
is_decoded_to('["^ ","foo",1]', {foo => 1});
is_decoded_to('[["^ ","foo",1],"bar"]', [{foo => 1}, "bar"]);
is_decoded_to('["^ ","foo",["^ ","bar",1]]', {foo => {bar => 1}});
# caching
is_decoded_to('[["^ ","foo",1,"fooo",1],["^ ","foo",1,"^0",1]]',[{foo => 1, fooo => 1}, {foo => 1, fooo => 1}]);
is_decoded_to('[["^ ","fooo",1],["^ ","^0",1]]', [{fooo => 1}, {fooo => 1}]);
# custom handlers
is_decoded_to('["~#point","2,3"]', Point->new(2,3), {point => PointReadHandler->new()});
is_decoded_to('[["~#point","2,3"],["^0","3,4"]]', [Point->new(2,3), Point->new(3,4)], {point => PointReadHandler->new()});
# types not in base perl
is_decoded_to('["^ ","~_",1]', {"" => 1});
is_decoded_to('["~#\'",true]', 1);
is_decoded_to('["~#\'",false]', 0);
is_decoded_to('["^ ","~?t",1]', {1 => 1});
is_decoded_to('["^ ","~?f",1]', {0 => 1});
is_decoded_to('["~#\'","~i123"]', 123);
is_decoded_to('["~#\'","~d123.456"]', 123.456);
done_testing();
sub is_decoded_to {
my ($json, $data, $handlers) = @_;
my $reader = Data::Transit::reader("json", handlers => $handlers);
return is_deeply($reader->read($json), $data);
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/URIID/Barcode.pm view on Meta::CPAN
my $data = $barcode->data;
Returns the data of the barcode.
The returned value might differ from the value passed to L</new> as it might have been normalised, decoded (character set), or otherwise altered.
No options are supported. However the options C<default>, and C<no_defaults> are ignored.
=head2 type
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/UUID/Concise.pm view on Meta::CPAN
use Data::UUID::Concise;
my $duc = Data::UUID::Concise->new();
my $encoded_uuid = $duc->encode((Data::UUID->new)->create);
my $decoded_uuid = $duc->decode('M55djt9tt4WoFaL68da9Ef');
$duc->alphabet('aaaaabcdefgh1230123');
$duc->alphabet; # 0123abcdefgh
=head1 ATTRIBUTES
lib/Data/UUID/Concise.pm view on Meta::CPAN
symbols.
=head2 decode
Decode a string with the appropriate set of symbols and return a
Data::UUID instance representing the decoded UUID.
=head1 FUNCTIONS
=head2 _normalize_alphabet
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/VRM/GB.pm view on Meta::CPAN
A function which takes a VRM as its first and only argument, and returns a
HASHREF with the keys C<start_date> and C<end_date>.
Each of those keys has as its value a DateTime object, truncated to the 'day'.
If the registration mark couldn't be decoded to a date, either
because it's of an unrecognised format or is using a letter prefix that is
not understood, then it will return undef.
Before comparing these dates with another DateTime, you must ensure you
truncate your DateTime to the day. If you have a time portion, you will
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Validate/Japanese.pm view on Meta::CPAN
=head1 METHODS
All methods return true or false unless otherwise stated.
All methods also expect Japanese characters that have successfully been
decoded to Perl's internal unicode format.
=head2 new()
Creates a new instance of Data::Validate::Japanese
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/Visitor/Encode.pm view on Meta::CPAN
$dev->decode($encoding, \@list);
$dev->decode($encoding, \$scalar);
$dev->decode($encoding, $scalar);
$dev->decode($encoding, $object);
Returns a structure containing nodes which are decoded from the specified
encoding.
=head2 decode_utf8
$dev->decode_utf8(\%hash);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Data/asXML.pm view on Meta::CPAN
}
# in safe_mode decode back the xml string and compare the data structures
if ($safe_mode) {
my $xml_string = $where->toString;
my $what_decoded = eval { $self->decode($xml_string) };
die 'encoding failed '.$@.' of '.eval('use Data::Dumper; Dumper([$what, $xml_string, $what_decoded])').' failed'
if not eq_deeply($what, $what_decoded);
# set back the safe mode after all was encoded
$self->safe_mode($safe_mode);
}
lib/Data/asXML.pm view on Meta::CPAN
sub decode {
my $self = shift;
my $xml = shift;
my $pos = shift || 1;
# in safe_mode "encode+decode" the decoded data for comparing
if ($self->safe_mode) {
$self->safe_mode(0);
my $data = $self->decode($xml, $pos);
my $data_redecoded = eval { $self->decode(
$self->encode($data)->toString,
$pos,
)};
die 'redecoding failed "'.$@.'" of '.eval('use Data::Dumper; Dumper([$xml, $data, $data_redecoded])').' failed'
if not eq_deeply($data, $data_redecoded);
$self->safe_mode(1);
return $data;
}
if (not $self->{'_cur_xpath_steps'}) {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/DataFlow/Proc/URLRetriever.pm view on Meta::CPAN
my $url =
$self->has_baseurl
? URI->new_abs( $_, $self->baseurl )->as_string
: $_;
return $self->ua->get($url)->decoded_content;
# TODO allow ArrayRef's instead of Str, and use the other elements
# as parameters for the get() method
};
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/DataStore/CAS/FS/DirCodec/Universal.pm view on Meta::CPAN
C<{ "*InvalidUTF8*": $bytes_as_codepoints }>
Any attribute which contains bytes >= 0x80 and which does not have Perl's
unicode flag set will be encoded this way, so that it comes back as it went in.
However, since filenames are intended to be human-readable, they are decoded as
unicode strings when appropriate, even if they arrived as octets which just
happened to be valid UTF-8.
=head1 METHODS
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Datahub/Factory/Indexer/Solr.pm view on Meta::CPAN
);
$response = $self->out->request($request);
if ($response->is_success) {
return decode_json($response->decoded_content);
} else {
Catmandu::HTTPError->throw({
code => $response->code,
message => $response->message,
url => $response->request->uri->as_string,
method => $response->request->method,
request_headers => [],
request_body => $response->request->content,
response_headers => [],
response_body => $response->decoded_content,
});
return undef;
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/DateTime/Format/JP.pm view on Meta::CPAN
=head1 DESCRIPTION
This module is used to parse and format Japanese date and time. It is lightweight and yet versatile.
It implements 2 main methods: L</parse_datetime> and L</format_datetime> both expect and return decoded utf8 string.
You can use L<Encode> to decode and encode from perl internal utf8 representation to real utf8 and vice versa.
=head1 METHODS
view all matches for this distribution
view release on metacpan or search on metacpan
lib/DateTime/Format/Japanese.pm view on Meta::CPAN
=head1 DESCRIPTION
This module implements a DateTime::Format module that can read Japanese
date notations and create a DateTime object, and vice versa.
All formatting methods will return a decoded utf-8 string, unless otherwise
specified explicitly via the output_encoding parameter.
All parsing methods expect a decoded utf-8 string, unless otherwise specified
explicitly via the input_encoding parameter
=head1 METHODS
=head2 new()
lib/DateTime/Format/Japanese.pm view on Meta::CPAN
This function will parse a Japanese date/time string and convert it to a
DateTime object. If the parsing is unsuccessful, it will croak.
Note that if you didn't provide a input_encoding parameter, the given
string is assumed to be decoded utf-8.
This function should be able to parse almost all of the common Japanese
date notations, whether they are written using ascii numerals, double byte
numerals, and kanji numerals. The date components (year, month, day or
era name, era year, month, day) must be present in the string. The time
view all matches for this distribution
view release on metacpan or search on metacpan
t/85.serialisation.t view on Meta::CPAN
my $orig = _make_fmt();
my $json_str = JSON::encode_json( $orig->TO_JSON );
ok( defined( $json_str ), 'JSON encode succeeded' );
my $state = JSON::decode_json( $json_str );
ok( ref( $state ) eq 'HASH', 'decoded JSON is a hashref' );
# Reconstruct from the decoded state
my $restored = DateTime::Format::Lite->new( %$state );
ok( defined( $restored ), 'reconstruct from JSON state succeeded' );
_check_state( $orig, $restored, 'JSON' );
};
};
view all matches for this distribution