| 1 | package JSON::Immutable::XS; | ||
| 2 | 2 | ▶ | use parent 'Export::XS'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use 5.020; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 2 | ▶ | use XS::Framework; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | JSON::Immutable::XS | ||
| 11 | |||
| 12 | =cut | ||
| 13 | |||
| 14 | 2 | our $VERSION = '0.1.3'; | |
| 15 | 2 | XS::Loader::bootstrap(); | |
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | Fast and simple abstract node-tree based storage with JSON support. Usefull for reading JSON configs, keeping it in the memory and don't worrying about mutability. Has XPath-like interface for data accessing. Easy to use with XS and C/C++ modules. | ||
| 20 | It use RapidJSON as JSON parser. L<https://rapidjson.org/> | ||
| 21 | |||
| 22 | =cut | ||
| 23 | |||
| 24 | =head1 SYNOPSIS | ||
| 25 | |||
| 26 | use JSON::Immutable::XS; | ||
| 27 | |||
| 28 | # you can provide this variable to XS and use it there | ||
| 29 | my $dict = JSON::Immutable::XS->new('example/dict.json'); | ||
| 30 | |||
| 31 | # get subnode by path ( any node is JSON::Immutable::XS ref) | ||
| 32 | my $node = $dict->get( 'path', 2, 'node'); # similar to ->{path}[2]{node} | ||
| 33 | |||
| 34 | # get() returns undef on not existed path | ||
| 35 | my $data = $node->get_value('this', 'is', 'the', 'way'); # data could be an any Perl Sv structure ( scalar, hash or array ) | ||
| 36 | |||
| 37 | # unless path will found - it'll return undef | ||
| 38 | # it possible to get keys from node as well | ||
| 39 | |||
| 40 | for ( @{$dict->keys()} ){ | ||
| 41 | ... | ||
| 42 | } | ||
| 43 | |||
| 44 | # use slice to get exactly that you need without unnecessary data ( detail description below )> | ||
| 45 | $dict->slice( 'path' ); | ||
| 46 | |||
| 47 | # see more features below | ||
| 48 | |||
| 49 | =cut | ||
| 50 | |||
| 51 | =head1 PERL INTERFACE | ||
| 52 | |||
| 53 | B<new()> | ||
| 54 | Creating of new instance. You can provide filename - it will be parsed as JSON | ||
| 55 | |||
| 56 | B<get()> | ||
| 57 | Finding a node by path (may be empty) and returning instance of node as ref 'JSON::Immutable::XS'. May be use any functions of this interface | ||
| 58 | |||
| 59 | B<get_value()> | ||
| 60 | Finding a node by path (may be empty) and returning Perl Sv. It could be Hash or Array or Scalar. | ||
| 61 | |||
| 62 | B<keys()> | ||
| 63 | Get keys of hash for node. Can use path. | ||
| 64 | |||
| 65 | B<exists()> | ||
| 66 | Checking of path existing. | ||
| 67 | |||
| 68 | B<slice()> | ||
| 69 | Get value by path for every key of hash or element of array. | ||
| 70 | |||
| 71 | B<export()> | ||
| 72 | Same as get_value() without path | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | =head1 AUTHOR | ||
| 77 | |||
| 78 | Vladimir Melnichenko <melnichenkovv@gmail.com>, Crazy Panda, CP Decision LTD | ||
| 79 | |||
| 80 | L<https://github.com/VMELNICHENKO/JSON-Immutable-XS> | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | =head1 LICENSE | ||
| 85 | |||
| 86 | You may distribute this code under the same terms as RapidJSON itself. L<https://rapidjson.org/> | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | 2 | 1; | |