| 1 | ############################################################################## | ||
| 2 | # | ||
| 3 | # Data::Tools::Serialization perl module | ||
| 4 | # Copyright (c) 2013-2024 Vladi Belperchinov-Shabanski "Cade" | ||
| 5 | # <cade@noxrun.com> <cade@bis.bg> <cade@cpan.org> | ||
| 6 | # http://cade.noxrun.com/ | ||
| 7 | # | ||
| 8 | # GPL | ||
| 9 | # | ||
| 10 | ############################################################################## | ||
| 11 | package Data::Tools::Serialization; | ||
| 12 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 1 | ▶ | use Exporter; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | |||
| 16 | 1 | our $VERSION = '1.60'; | |
| 17 | |||
| 18 | 1 | our @ISA = qw( Exporter ); | |
| 19 | 1 | our @EXPORT = qw( | |
| 20 | |||
| 21 | xml2perl | ||
| 22 | perl2xml | ||
| 23 | |||
| 24 | json2perl | ||
| 25 | perl2json | ||
| 26 | |||
| 27 | ); | ||
| 28 | |||
| 29 | 1 | our %EXPORT_TAGS = ( | |
| 30 | |||
| 31 | 'all' => \@EXPORT, | ||
| 32 | 'none' => [], | ||
| 33 | |||
| 34 | ); | ||
| 35 | |||
| 36 | ############################################################################## | ||
| 37 | |||
| 38 | BEGIN | ||
| 39 | 1 | ▶ | { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 40 | 1 | eval { require XML::Bare; }; | |
| 41 | 1 | eval { require JSON; }; | |
| 42 | } | ||
| 43 | |||
| 44 | sub xml2perl | ||
| 45 | 1 | ▶ | { |
|
Subroutine
xml2perl: called CC=1 SCAR=0.0
Pod
documented
| |||
| 46 | 1 | my $ob = new XML::Bare( text => shift() ); | |
| 47 | 1 | return $ob->parse(); | |
| 48 | } | ||
| 49 | |||
| 50 | sub perl2xml | ||
| 51 | 1 | ▶ | { |
|
Subroutine
perl2xml: called CC=1 SCAR=0.0
Pod
documented
| |||
| 52 | 1 | return XML::Bare::obj2xml( shift() ); | |
| 53 | } | ||
| 54 | |||
| 55 | sub json2perl | ||
| 56 | 4 | ▶ | { |
|
Subroutine
json2perl: called CC=1 SCAR=0.0
Pod
documented
| |||
| 57 | 4 | return JSON::decode_json( shift ); | |
| 58 | } | ||
| 59 | |||
| 60 | sub perl2json | ||
| 61 | 3 | ▶ | { |
|
Subroutine
perl2json: called CC=1 SCAR=0.0
Pod
documented
| |||
| 62 | 3 | return JSON::encode_json( shift ); | |
| 63 | } | ||
| 64 | |||
| 65 | ############################################################################## | ||
| 66 | |||
| 67 | =pod | ||
| 68 | |||
| 69 | |||
| 70 | =head1 NAME | ||
| 71 | |||
| 72 | Data::Tools::Serialization provides set of high-level serialization | ||
| 73 | and deserialization wrapper functions. | ||
| 74 | |||
| 75 | =head1 SYNOPSIS | ||
| 76 | |||
| 77 | use Data::Tools::Serialization qw( :all ); # import all functions | ||
| 78 | use Data::Tools::Serialization; # the same as :all :) | ||
| 79 | use Data::Tools::Serialization qw( :none ); # do not import anything | ||
| 80 | |||
| 81 | # -------------------------------------------------------------------------- | ||
| 82 | |||
| 83 | my $perl_hoh = xml2perl( $xml_text ); | ||
| 84 | my $xml_text = perl2xml( $perl_hoh ); | ||
| 85 | |||
| 86 | my $perl_hoh = json2perl( $json_text ); | ||
| 87 | my $json_text = perl2json( $perl_hoh ); | ||
| 88 | |||
| 89 | # -------------------------------------------------------------------------- | ||
| 90 | |||
| 91 | =head1 FUNCTIONS | ||
| 92 | |||
| 93 | =head2 xml2perl( $xml_text ) | ||
| 94 | |||
| 95 | Returns perl hash of hashes reference representing the XML data text. | ||
| 96 | |||
| 97 | =head2 perl2xml( $perl_hoh ) | ||
| 98 | |||
| 99 | Returns xml text representing the in-memory perl hash of hashes structure. | ||
| 100 | |||
| 101 | =head2 json2perl( $xml_text ) | ||
| 102 | |||
| 103 | Returns perl hash of hashes reference representing the JSON data text. | ||
| 104 | |||
| 105 | =head2 perl2json( $perl_hoh ) | ||
| 106 | |||
| 107 | Returns JSON text representing the in-memory perl hash of hashes structure. | ||
| 108 | |||
| 109 | =head1 REQUIRED MODULES | ||
| 110 | |||
| 111 | Data::Tools::Serialization uses: | ||
| 112 | |||
| 113 | * XML::Bare | ||
| 114 | * JSON | ||
| 115 | |||
| 116 | all are loaded on demand and are not initial requirement nor if just other | ||
| 117 | parts of the Data::Tools are used. | ||
| 118 | |||
| 119 | =head1 GITHUB REPOSITORY | ||
| 120 | |||
| 121 | git@github.com:cade-vs/perl-data-tools.git | ||
| 122 | |||
| 123 | git clone git://github.com/cade-vs/perl-data-tools.git | ||
| 124 | |||
| 125 | =head1 AUTHOR | ||
| 126 | |||
| 127 | Vladi Belperchinov-Shabanski "Cade" | ||
| 128 | <cade@noxrun.com> <cade@bis.bg> <cade@cpan.org> | ||
| 129 | http://cade.noxrun.com/ | ||
| 130 | |||
| 131 | |||
| 132 | =cut | ||
| 133 | |||
| 134 | ############################################################################## | ||
| 135 | 1 | 1; | |