Skip to content

Instantly share code, notes, and snippets.

@akzhan akzhan/JSON.pm
Created Dec 28, 2016

Embed
What would you like to do?
package BUX::Util::JSON;
=encoding utf-8
=head1 NAME
BUX::Util::JSON
=head1 SYNOPSYS
use BUX::Util::JSON qw( data_to_json data_from_json );
=head1 DESCRIPTION
Получает на вход JSON в виде строки с флагом utf-8.
Или возвращает JSON в виде строки с флагом utf-8.
=cut
use strict;
use warnings;
use utf8;
use JSON::XS ();
use Encode qw( encode_utf8 decode_utf8 );
use Exporter qw( import );
my $jsoner = JSON::XS->new->utf8->allow_nonref;
=head1 METHODS
=head2 data_to_json
my $json_str = data_to_json( $scalar_or_ref );
=cut
sub data_to_json {
return decode_utf8( $jsoner->encode( $_[0] ) );
}
=head2 data_from_json
my $scalar_or_ref = data_from_json( $json_str );
=cut
sub data_from_json {
return $jsoner->decode( encode_utf8( $_[0] ) );
}
our @EXPORT_OK = qw(
&data_to_json
&data_from_json
);
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.