Aion-Format

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

      },
      "runtime" : {
         "recommends" : {
            "Devel::Size" : "0"
         },
         "requires" : {
            "DDP" : "0",
            "Encode" : "0",
            "Exporter" : "0",
            "Guard" : "0",
            "JSON::XS" : "0",
            "List::Util" : "0",
            "POSIX" : "0",
            "Term::ANSIColor" : "0",
            "YAML::Syck" : "0",
            "bigint" : "0",
            "bytes" : "0",
            "common::sense" : "0",
            "config" : "0",
            "constant" : "0",
            "perl" : "v5.22.0"

META.json  view on Meta::CPAN

         "url" : "https://github.com/darviarush/perl-aion-format.git",
         "web" : "https://github.com/darviarush/perl-aion-format"
      }
   },
   "version" : "0.1.2",
   "x_authority" : "cpan:DART",
   "x_contributors" : [
      "Yaroslav O. Kosmina <dart@cpan.org>",
      "Yaroslav O. Kosmina <darviarush@mail.ru>"
   ],
   "x_serialization_backend" : "JSON::PP version 4.16",
   "x_static_install" : 0
}

META.yml  view on Meta::CPAN

    file: lib/Aion/Format/Url.pm
  Aion::Format::Yaml:
    file: lib/Aion/Format/Yaml.pm
recommends:
  Devel::Size: '0'
requires:
  DDP: '0'
  Encode: '0'
  Exporter: '0'
  Guard: '0'
  JSON::XS: '0'
  List::Util: '0'
  POSIX: '0'
  Term::ANSIColor: '0'
  YAML::Syck: '0'
  bigint: '0'
  bytes: '0'
  common::sense: '0'
  config: '0'
  constant: '0'
  perl: v5.22.0

cpanfile  view on Meta::CPAN

	requires 'open';
};

# Для DDP
recommends 'Devel::Size';

requires 'DDP';
requires 'Guard';
requires 'Encode';
requires 'Exporter';
requires 'JSON::XS';
requires 'List::Util';
requires 'POSIX';
requires 'Term::ANSIColor';
requires 'YAML::Syck';
requires 'bigint';
requires 'bytes';
requires 'common::sense';
requires 'config';
requires 'constant';

i18n/Aion/Format/Json.ru-en.po  view on Meta::CPAN

msgid "Aion::Format::Json - расширение Perl для форматирования JSON"
msgstr "Aion::Format::Json - Perl extension for JSON formatting"

msgid "`Aion::Format::Json` использует в качестве основы `JSON::XS`. И включает следующие настройки:"
msgstr "`Aion::Format::Json` uses `JSON::XS` as a base. And includes the following settings:"

msgid ""
"* allow_nonref — скаляры кодирования и декодирования.\n"
"* indent – включить многострочный текст с отступом в начале строки.\n"
"* space_after — `\\n` после json.\n"
"* canonical — сортировка ключей в хешах."
msgstr ""
"* allow_nonref - encoding and decoding scalars.\n"
"* indent – enable multiline text with indentation at the beginning of the line.\n"
"* space_after — `\\n` after json.\n"
"* canonical - sorting keys in hashes."

msgid "Переводит данные в формат json."
msgstr "Converts data to json format."

msgid "Разбирает строку в формате JSON в структуру Perl."
msgstr "Parses a JSON string into a Perl structure."

msgid "âš– **GPLv3**"
msgstr "âš– **GPLv3**"

msgid "The Aion::Format::Json module is copyright © 2023 Yaroslav O. Kosmina. Rusland. All rights reserved."
msgstr "The Aion::Format::Json module is copyright © 2023 Yaroslav O. Kosmina. Rusland. All rights reserved."

lib/Aion/Format/Json.md  view on Meta::CPAN

!ru:en
# NAME

Aion::Format::Json - расширение Perl для форматирования JSON

# SYNOPSIS

```perl
use Aion::Format::Json;

to_json {a => 10}    # => {\n   "a": 10\n}\n
from_json '[1, "5"]' # --> [1, "5"]
```

# DESCRIPTION

`Aion::Format::Json` использует в качестве основы `JSON::XS`. И включает следующие настройки:

* allow_nonref — скаляры кодирования и декодирования.
* indent – включить многострочный текст с отступом в начале строки.
* space_after — `\n` после json.
* canonical — сортировка ключей в хешах.

# SUBROUTINES

## to_json (;$data)

lib/Aion/Format/Json.md  view on Meta::CPAN

';

to_json $data # -> $result

local $_ = $data;
to_json # -> $result
```

## from_json (;$string)

Разбирает строку в формате JSON в структуру Perl.

```perl
from_json '{"a": 10}' # --> {a => 10}

[map from_json, "{}", "2"]  # --> [{}, 2]
```

# AUTHOR

Yaroslav O. Kosmina <darviarush@mail.ru>

lib/Aion/Format/Json.pm  view on Meta::CPAN

package Aion::Format::Json;

use common::sense;
use JSON::XS qw//;

use Exporter qw/import/;
our @EXPORT = our @EXPORT_OK = grep {
    *{$Aion::Format::Json::{$_}}{CODE} && !/^(_|(NaN|import)\z)/n
} keys %Aion::Format::Json::;

#@category json

# Настраиваем json
our $JSON = JSON::XS->new->allow_nonref->indent(1)->space_after(1)->canonical(1);

# Ð’ json
sub to_json(;$) {
	$JSON->encode(@_ == 0? $_: @_)
}

# Из json
sub from_json(;$) {
	$JSON->decode(@_ == 0? $_: @_)
}

1;

__END__

=encoding utf-8

=head1 NAME

Aion::Format::Json - Perl extension for JSON formatting

=head1 SYNOPSIS

	use Aion::Format::Json;
	
	to_json {a => 10}    # => {\n   "a": 10\n}\n
	from_json '[1, "5"]' # --> [1, "5"]

=head1 DESCRIPTION

C<Aion::Format::Json> uses C<JSON::XS> as a base. And includes the following settings:

=over

=item * allow_nonref - encoding and decoding scalars.

=item * indent – enable multiline text with indentation at the beginning of the line.

=item * space_after — C<\n> after json.

=item * canonical - sorting keys in hashes.

lib/Aion/Format/Json.pm  view on Meta::CPAN

	}
	';
	
	to_json $data # -> $result
	
	local $_ = $data;
	to_json # -> $result

=head2 from_json (;$string)

Parses a JSON string into a Perl structure.

	from_json '{"a": 10}' # --> {a => 10}
	
	[map from_json, "{}", "2"]  # --> [{}, 2]

=head1 AUTHOR

Yaroslav O. Kosmina L<mailto:darviarush@mail.ru>

=head1 LICENSE

t/aion/format/json.t  view on Meta::CPAN

use common::sense; use open qw/:std :utf8/;  use Carp qw//; use Cwd qw//; use File::Basename qw//; use File::Find qw//; use File::Slurper qw//; use File::Spec qw//; use File::Path qw//; use Scalar::Util qw//;  use Test::More 0.98;  use String::Diff q...
# # NAME
# 
# Aion::Format::Json - расширение Perl для форматирования JSON
# 
# # SYNOPSIS
# 
subtest 'SYNOPSIS' => sub { 
use Aion::Format::Json;

local ($::_g0 = do {to_json {a => 10}}, $::_e0 = "{\n   \"a\": 10\n}\n"); ::ok $::_g0 eq $::_e0, 'to_json {a => 10}    # => {\n   "a": 10\n}\n' or ::diag ::_string_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;
local ($::_g0 = do {from_json '[1, "5"]'}, $::_e0 = do {[1, "5"]}); ::is_deeply $::_g0, $::_e0, 'from_json \'[1, "5"]\' # --> [1, "5"]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;

# 
# # DESCRIPTION
# 
# `Aion::Format::Json` использует в качестве основы `JSON::XS`. И включает следующие настройки:
# 
# * allow_nonref — скаляры кодирования и декодирования.
# * indent – включить многострочный текст с отступом в начале строки.
# * space_after — `\n` после json.
# * canonical — сортировка ключей в хешах.
# 
# # SUBROUTINES
# 
# ## to_json (;$data)
# 

t/aion/format/json.t  view on Meta::CPAN

';

local ($::_g0 = do {to_json $data}, $::_e0 = do {$result}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, 'to_json $data # -> $result' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;

local $_ = $data;
local ($::_g0 = do {to_json}, $::_e0 = do {$result}); ::ok defined($::_g0) == defined($::_e0) && $::_g0 eq $::_e0, 'to_json # -> $result' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;

# 
# ## from_json (;$string)
# 
# Разбирает строку в формате JSON в структуру Perl.
# 
::done_testing; }; subtest 'from_json (;$string)' => sub { 
local ($::_g0 = do {from_json '{"a": 10}'}, $::_e0 = do {{a => 10}}); ::is_deeply $::_g0, $::_e0, 'from_json \'{"a": 10}\' # --> {a => 10}' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;

local ($::_g0 = do {[map from_json, "{}", "2"]}, $::_e0 = do {[{}, 2]}); ::is_deeply $::_g0, $::_e0, '[map from_json, "{}", "2"]  # --> [{}, 2]' or ::diag ::_struct_diff($::_g0, $::_e0); undef $::_g0; undef $::_e0;

# 
# # AUTHOR
# 
# Yaroslav O. Kosmina <darviarush@mail.ru>



( run in 2.182 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )