| Filename | C:/tmp64ng/perl/lib/JSON/PP.pm | 
| Statements | Executed 217270 statements in 203ms | 
| Calls | P | F | Exclusive Time  | 
        Inclusive Time  | 
        Subroutine | 
|---|---|---|---|---|---|
| 22642 | 16 | 1 | 46.8ms | 46.8ms | JSON::PP::next_chr | 
| 1406 | 2 | 1 | 31.2ms | 78.0ms | JSON::PP::string | 
| 734 | 2 | 1 | 31.2ms | 46.8ms | JSON::PP::value_to_json | 
| 1 | 1 | 1 | 15.6ms | 15.6ms | JSON::PP::BEGIN@11 | 
| 3426 | 2 | 1 | 15.6ms | 15.6ms | JSON::PP::CORE:subst (opcode) | 
| 465 | 1 | 1 | 15.6ms | 93.6ms | JSON::PP::hash_to_json (recurses: max depth 3, inclusive time 15.6ms) | 
| 374 | 1 | 1 | 15.6ms | 109ms | JSON::PP::object (recurses: max depth 3, inclusive time 15.6ms) | 
| 1321 | 4 | 1 | 15.6ms | 93.6ms | JSON::PP::object_to_json (recurses: max depth 5, inclusive time 125ms) | 
| 1713 | 2 | 1 | 15.6ms | 31.2ms | JSON::PP::string_to_json | 
| 1067 | 3 | 1 | 15.6ms | 109ms | JSON::PP::value (recurses: max depth 4, inclusive time 62.4ms) | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@10 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@1269 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@1332 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@21 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@22 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@23 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@24 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@25 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@26 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@27 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@28 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@29 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@30 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@31 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@32 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@34 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@35 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@36 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@37 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@38 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@39 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@41 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@43 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@45 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@5 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@584 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@6 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@667 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@7 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::BEGIN@8 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::Boolean::BEGIN@1403 | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::Boolean::__ANON__[:1404] | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::Boolean::__ANON__[:1405] | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::Boolean::__ANON__[:1406] | 
| 17361 | 10 | 1 | 0s | 0s | JSON::PP::CORE:match (opcode) | 
| 96 | 1 | 1 | 0s | 0s | JSON::PP::CORE:sort (opcode) | 
| 55 | 1 | 1 | 0s | 0s | JSON::PP::CORE:unpack (opcode) | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::IncrParser::BEGIN@1415 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::IncrParser::BEGIN@1417 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::IncrParser::BEGIN@1418 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::IncrParser::BEGIN@1419 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::IncrParser::BEGIN@1420 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::IncrParser::BEGIN@1421 | 
| 1 | 1 | 1 | 0s | 0s | JSON::PP::IncrParser::BEGIN@1422 | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::IncrParser::_incr_parse | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::IncrParser::incr_parse | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::IncrParser::incr_reset | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::IncrParser::incr_skip | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::IncrParser::incr_text | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::IncrParser::new | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::PP_decode_box | 
| 55 | 1 | 1 | 0s | 109ms | JSON::PP::PP_decode_json | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::PP_encode_box | 
| 63 | 1 | 1 | 0s | 93.6ms | JSON::PP::PP_encode_json | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::__ANON__[:1345] | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::__ANON__[:134] | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::__ANON__[:1366] | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::__ANON__[:1383] | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::__ANON__[:281] | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::__ANON__[:286] | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::_decode_surrogates | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::_decode_unicode | 
| 123 | 2 | 1 | 0s | 0s | JSON::PP::_down_indent | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::_encode_ascii | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::_encode_latin1 | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::_encode_surrogates | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::_is_bignum | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::_json_object_hook | 
| 465 | 1 | 1 | 0s | 0s | JSON::PP::_sort | 
| 123 | 2 | 1 | 0s | 0s | JSON::PP::_up_indent | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::allow_bigint | 
| 106 | 1 | 1 | 0s | 0s | JSON::PP::array | 
| 130 | 1 | 1 | 0s | 15.6ms | JSON::PP::array_to_json | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::bareKey | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::blessed_to_json | 
| 55 | 2 | 2 | 0s | 109ms | JSON::PP::decode | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::decode_error | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::decode_json | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::decode_prefix | 
| 63 | 2 | 2 | 0s | 93.6ms | JSON::PP::encode | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::encode_error | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::encode_json | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::false | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::filter_json_object | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::filter_json_single_key_object | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::from_json | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::get_indent_length | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::get_max_depth | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::get_max_size | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::incr_parse | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::incr_reset | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::incr_skip | 
| 9 | 1 | 1 | 0s | 0s | JSON::PP::indent_length | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::is_bool | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::is_valid_utf8 | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::max_depth | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::max_size | 
| 64 | 3 | 3 | 0s | 0s | JSON::PP::new | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::null | 
| 54 | 1 | 1 | 0s | 0s | JSON::PP::number | 
| 9 | 1 | 1 | 0s | 0s | JSON::PP::pretty | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::sort_by | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::to_json | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::true | 
| 4111 | 10 | 1 | 0s | 0s | JSON::PP::white | 
| 0 | 0 | 0 | 0s | 0s | JSON::PP::word | 
| Line | State ments  | 
      Time on line  | 
      Calls | Time in subs  | 
      Code | 
|---|---|---|---|---|---|
| 1 | package JSON::PP; | ||||
| 2 | |||||
| 3 | # JSON-2.0 | ||||
| 4 | |||||
| 5 | 2 | 0s | 1 | 0s | # spent 0s within JSON::PP::BEGIN@5 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 5 # spent     0s making 1 call to JSON::PP::BEGIN@5  | 
| 6 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@6 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 6 # spent     0s making 1 call to JSON::PP::BEGIN@6
# spent     0s making 1 call to strict::import  | 
| 7 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@7 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 7 # spent     0s making 1 call to JSON::PP::BEGIN@7
# spent     0s making 1 call to base::import  | 
| 8 | 2 | 0s | 1 | 0s | # spent 0s within JSON::PP::BEGIN@8 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 8 # spent     0s making 1 call to JSON::PP::BEGIN@8  | 
| 9 | |||||
| 10 | 2 | 0s | 1 | 0s | # spent 0s within JSON::PP::BEGIN@10 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 10 # spent     0s making 1 call to JSON::PP::BEGIN@10  | 
| 11 | 2 | 0s | 1 | 15.6ms | # spent 15.6ms within JSON::PP::BEGIN@11 which was called:
#    once (15.6ms+0s) by Parse::CPAN::Meta::_can_load at line 11 # spent  15.6ms making 1 call to JSON::PP::BEGIN@11  | 
| 12 | #use Devel::Peek; | ||||
| 13 | |||||
| 14 | 1 | 0s | $JSON::PP::VERSION = '2.27300'; | ||
| 15 | |||||
| 16 | 1 | 0s | @JSON::PP::EXPORT = qw(encode_json decode_json from_json to_json); | ||
| 17 | |||||
| 18 | # instead of hash-access, i tried index-access for speed. | ||||
| 19 | # but this method is not faster than what i expected. so it will be changed. | ||||
| 20 | |||||
| 21 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@21 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 21 # spent     0s making 1 call to JSON::PP::BEGIN@21
# spent     0s making 1 call to constant::import  | 
| 22 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@22 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 22 # spent     0s making 1 call to JSON::PP::BEGIN@22
# spent     0s making 1 call to constant::import  | 
| 23 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@23 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 23 # spent     0s making 1 call to JSON::PP::BEGIN@23
# spent     0s making 1 call to constant::import  | 
| 24 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@24 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 24 # spent     0s making 1 call to JSON::PP::BEGIN@24
# spent     0s making 1 call to constant::import  | 
| 25 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@25 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 25 # spent     0s making 1 call to JSON::PP::BEGIN@25
# spent     0s making 1 call to constant::import  | 
| 26 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@26 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 26 # spent     0s making 1 call to JSON::PP::BEGIN@26
# spent     0s making 1 call to constant::import  | 
| 27 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@27 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 27 # spent     0s making 1 call to JSON::PP::BEGIN@27
# spent     0s making 1 call to constant::import  | 
| 28 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@28 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 28 # spent     0s making 1 call to JSON::PP::BEGIN@28
# spent     0s making 1 call to constant::import  | 
| 29 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@29 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 29 # spent     0s making 1 call to JSON::PP::BEGIN@29
# spent     0s making 1 call to constant::import  | 
| 30 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@30 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 30 # spent     0s making 1 call to JSON::PP::BEGIN@30
# spent     0s making 1 call to constant::import  | 
| 31 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@31 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 31 # spent     0s making 1 call to JSON::PP::BEGIN@31
# spent     0s making 1 call to constant::import  | 
| 32 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@32 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 32 # spent     0s making 1 call to JSON::PP::BEGIN@32
# spent     0s making 1 call to constant::import  | 
| 33 | |||||
| 34 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@34 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 34 # spent     0s making 1 call to JSON::PP::BEGIN@34
# spent     0s making 1 call to constant::import  | 
| 35 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@35 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 35 # spent     0s making 1 call to JSON::PP::BEGIN@35
# spent     0s making 1 call to constant::import  | 
| 36 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@36 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 36 # spent     0s making 1 call to JSON::PP::BEGIN@36
# spent     0s making 1 call to constant::import  | 
| 37 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@37 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 37 # spent     0s making 1 call to JSON::PP::BEGIN@37
# spent     0s making 1 call to constant::import  | 
| 38 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@38 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 38 # spent     0s making 1 call to JSON::PP::BEGIN@38
# spent     0s making 1 call to constant::import  | 
| 39 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@39 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 39 # spent     0s making 1 call to JSON::PP::BEGIN@39
# spent     0s making 1 call to constant::import  | 
| 40 | |||||
| 41 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@41 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 41 # spent     0s making 1 call to JSON::PP::BEGIN@41
# spent     0s making 1 call to constant::import  | 
| 42 | |||||
| 43 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@43 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 43 # spent     0s making 1 call to JSON::PP::BEGIN@43
# spent     0s making 1 call to constant::import  | 
| 44 | |||||
| 45 | # spent 0s within JSON::PP::BEGIN@45 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 86  | ||||
| 46 | 1 | 0s | my @xs_compati_bit_properties = qw( | ||
| 47 | latin1 ascii utf8 indent canonical space_before space_after allow_nonref shrink | ||||
| 48 | allow_blessed convert_blessed relaxed allow_unknown | ||||
| 49 | ); | ||||
| 50 | 1 | 0s | my @pp_bit_properties = qw( | ||
| 51 | allow_singlequote allow_bignum loose | ||||
| 52 | allow_barekey escape_slash as_nonblessed | ||||
| 53 | ); | ||||
| 54 | |||||
| 55 | # Perl version check, Unicode handling is enable? | ||||
| 56 | # Helper module sets @JSON::PP::_properties. | ||||
| 57 | 1 | 0s | if ($] < 5.008 ) { | ||
| 58 | my $helper = $] >= 5.006 ? 'JSON::PP::Compat5006' : 'JSON::PP::Compat5005'; | ||||
| 59 | eval qq| require $helper |; | ||||
| 60 | if ($@) { Carp::croak $@; } | ||||
| 61 | } | ||||
| 62 | |||||
| 63 | 1 | 0s | for my $name (@xs_compati_bit_properties, @pp_bit_properties) { | ||
| 64 | 19 | 0s | my $flag_name = 'P_' . uc($name); | ||
| 65 | |||||
| 66 | 19 | 0s |         eval qq/         # spent  15.6ms executing statements in string eval # includes 15.6ms spent executing 54 calls to 2 subs defined therein. # spent 0s executing statements in string eval # includes 0s spent executing 9 calls to 2 subs defined therein. # spent 0s executing statements in string eval # includes 0s spent executing 9 calls to 2 subs defined therein. # spent 0s executing statements in string eval # includes 0s spent executing 9 calls to 2 subs defined therein. # spent 0s executing statements in string eval # includes 0s spent executing 9 calls to 2 subs defined therein. # spent 0s executing statements in string eval # includes 0s spent executing 54 calls to 2 subs defined therein. # spent 0s executing statements in string eval # includes 0s spent executing 54 calls to 2 subs defined therein.  | ||
| 67 | sub $name { | ||||
| 68 | my \$enable = defined \$_[1] ? \$_[1] : 1; | ||||
| 69 | |||||
| 70 | if (\$enable) { | ||||
| 71 | \$_[0]->{PROPS}->[$flag_name] = 1; | ||||
| 72 | } | ||||
| 73 | else { | ||||
| 74 | \$_[0]->{PROPS}->[$flag_name] = 0; | ||||
| 75 | } | ||||
| 76 | |||||
| 77 | \$_[0]; | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | sub get_$name { | ||||
| 81 | \$_[0]->{PROPS}->[$flag_name] ? 1 : ''; | ||||
| 82 | } | ||||
| 83 | /; | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | 1 | 0s | 1 | 0s | } # spent     0s making 1 call to JSON::PP::BEGIN@45  | 
| 87 | |||||
| - - | |||||
| 90 | # Functions | ||||
| 91 | |||||
| 92 | my %encode_allow_method | ||||
| 93 | 1 | 0s | = map {($_ => 1)} qw/utf8 pretty allow_nonref latin1 self_encode escape_slash | ||
| 94 | allow_blessed convert_blessed indent indent_length allow_bignum | ||||
| 95 | as_nonblessed | ||||
| 96 | /; | ||||
| 97 | my %decode_allow_method | ||||
| 98 | 1 | 0s | = map {($_ => 1)} qw/utf8 allow_nonref loose allow_singlequote allow_bignum | ||
| 99 | allow_barekey max_size relaxed/; | ||||
| 100 | |||||
| 101 | |||||
| 102 | 1 | 0s | my $JSON; # cache | ||
| 103 | |||||
| 104 | sub encode_json ($) { # encode | ||||
| 105 | ($JSON ||= __PACKAGE__->new->utf8)->encode(@_); | ||||
| 106 | } | ||||
| 107 | |||||
| 108 | |||||
| 109 | sub decode_json { # decode | ||||
| 110 | ($JSON ||= __PACKAGE__->new->utf8)->decode(@_); | ||||
| 111 | } | ||||
| 112 | |||||
| 113 | # Obsoleted | ||||
| 114 | |||||
| 115 | sub to_json($) { | ||||
| 116 | Carp::croak ("JSON::PP::to_json has been renamed to encode_json."); | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | |||||
| 120 | sub from_json($) { | ||||
| 121 | Carp::croak ("JSON::PP::from_json has been renamed to decode_json."); | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | |||||
| 125 | # Methods | ||||
| 126 | |||||
| 127 | # spent 0s within JSON::PP::new which was called 64 times, avg 0s/call:
# 54 times (0s+0s) by CPAN::Meta::Converter::_dclone at line 56 of CPAN/Meta/Converter.pm, avg 0s/call
#  9 times (0s+0s) by CPAN::Meta::as_string at line 612 of CPAN/Meta.pm, avg 0s/call
#     once (0s+0s) by Parse::CPAN::Meta::load_json_string at line 52 of Parse/CPAN/Meta.pm  | ||||
| 128 | 64 | 0s | my $class = shift; | ||
| 129 | my $self = { | ||||
| 130 | max_depth => 512, | ||||
| 131 | max_size => 0, | ||||
| 132 | indent => 0, | ||||
| 133 | FLAGS => 0, | ||||
| 134 | fallback => sub { encode_error('Invalid value. JSON can only reference.') }, | ||||
| 135 | 64 | 0s | indent_length => 3, | ||
| 136 | }; | ||||
| 137 | |||||
| 138 | 64 | 0s | bless $self, $class; | ||
| 139 | } | ||||
| 140 | |||||
| 141 | |||||
| 142 | # spent 93.6ms (0s+93.6) within JSON::PP::encode which was called 63 times, avg 1.49ms/call:
# 54 times (0s+78.0ms) by CPAN::Meta::Converter::_dclone at line 60 of CPAN/Meta/Converter.pm, avg 1.44ms/call
#  9 times (0s+15.6ms) by CPAN::Meta::as_string at line 612 of CPAN/Meta.pm, avg 1.73ms/call  | ||||
| 143 | 63 | 0s | 63 | 93.6ms |     return $_[0]->PP_encode_json($_[1]);     # spent  93.6ms making 63 calls to JSON::PP::PP_encode_json, avg 1.49ms/call  | 
| 144 | } | ||||
| 145 | |||||
| 146 | |||||
| 147 | # spent 109ms (0s+109) within JSON::PP::decode which was called 55 times, avg 1.99ms/call:
# 54 times (0s+109ms) by CPAN::Meta::Converter::_dclone at line 60 of CPAN/Meta/Converter.pm, avg 2.02ms/call
#     once (0s+0s) by Parse::CPAN::Meta::load_json_string at line 52 of Parse/CPAN/Meta.pm  | ||||
| 148 | 55 | 0s | 55 | 109ms |     return $_[0]->PP_decode_json($_[1], 0x00000000);     # spent   109ms making 55 calls to JSON::PP::PP_decode_json, avg 1.99ms/call  | 
| 149 | } | ||||
| 150 | |||||
| 151 | |||||
| 152 | sub decode_prefix { | ||||
| 153 | return $_[0]->PP_decode_json($_[1], 0x00000001); | ||||
| 154 | } | ||||
| 155 | |||||
| 156 | |||||
| 157 | # accessor | ||||
| 158 | |||||
| 159 | |||||
| 160 | # pretty printing | ||||
| 161 | |||||
| 162 | # spent 0s within JSON::PP::pretty which was called 9 times, avg 0s/call:
# 9 times (0s+0s) by CPAN::Meta::as_string at line 612 of CPAN/Meta.pm, avg 0s/call  | ||||
| 163 | 9 | 0s | my ($self, $v) = @_; | ||
| 164 | 9 | 0s | my $enable = defined $v ? $v : 1; | ||
| 165 | |||||
| 166 | 9 | 0s | 36 | 0s |     if ($enable) { # indent_length(3) for JSON::XS compatibility     # spent     0s making 9 calls to JSON::PP::indent, avg 0s/call
    # spent     0s making 9 calls to JSON::PP::indent_length, avg 0s/call
    # spent     0s making 9 calls to JSON::PP::space_after, avg 0s/call
    # spent     0s making 9 calls to JSON::PP::space_before, avg 0s/call  | 
| 167 | $self->indent(1)->indent_length(3)->space_before(1)->space_after(1); | ||||
| 168 | } | ||||
| 169 | else { | ||||
| 170 | $self->indent(0)->space_before(0)->space_after(0); | ||||
| 171 | } | ||||
| 172 | |||||
| 173 | 9 | 0s | $self; | ||
| 174 | } | ||||
| 175 | |||||
| 176 | # etc | ||||
| 177 | |||||
| 178 | sub max_depth { | ||||
| 179 | my $max = defined $_[1] ? $_[1] : 0x80000000; | ||||
| 180 | $_[0]->{max_depth} = $max; | ||||
| 181 | $_[0]; | ||||
| 182 | } | ||||
| 183 | |||||
| 184 | |||||
| 185 | sub get_max_depth { $_[0]->{max_depth}; } | ||||
| 186 | |||||
| 187 | |||||
| 188 | sub max_size { | ||||
| 189 | my $max = defined $_[1] ? $_[1] : 0; | ||||
| 190 | $_[0]->{max_size} = $max; | ||||
| 191 | $_[0]; | ||||
| 192 | } | ||||
| 193 | |||||
| 194 | |||||
| 195 | sub get_max_size { $_[0]->{max_size}; } | ||||
| 196 | |||||
| 197 | |||||
| 198 | sub filter_json_object { | ||||
| 199 | $_[0]->{cb_object} = defined $_[1] ? $_[1] : 0; | ||||
| 200 | $_[0]->{F_HOOK} = ($_[0]->{cb_object} or $_[0]->{cb_sk_object}) ? 1 : 0; | ||||
| 201 | $_[0]; | ||||
| 202 | } | ||||
| 203 | |||||
| 204 | sub filter_json_single_key_object { | ||||
| 205 | if (@_ > 1) { | ||||
| 206 | $_[0]->{cb_sk_object}->{$_[1]} = $_[2]; | ||||
| 207 | } | ||||
| 208 | $_[0]->{F_HOOK} = ($_[0]->{cb_object} or $_[0]->{cb_sk_object}) ? 1 : 0; | ||||
| 209 | $_[0]; | ||||
| 210 | } | ||||
| 211 | |||||
| 212 | # spent 0s within JSON::PP::indent_length which was called 9 times, avg 0s/call:
# 9 times (0s+0s) by JSON::PP::pretty at line 166, avg 0s/call  | ||||
| 213 | 9 | 0s | if (!defined $_[1] or $_[1] > 15 or $_[1] < 0) { | ||
| 214 | Carp::carp "The acceptable range of indent_length() is 0 to 15."; | ||||
| 215 | } | ||||
| 216 | else { | ||||
| 217 | 9 | 0s | $_[0]->{indent_length} = $_[1]; | ||
| 218 | } | ||||
| 219 | 9 | 0s | $_[0]; | ||
| 220 | } | ||||
| 221 | |||||
| 222 | sub get_indent_length { | ||||
| 223 | $_[0]->{indent_length}; | ||||
| 224 | } | ||||
| 225 | |||||
| 226 | sub sort_by { | ||||
| 227 | $_[0]->{sort_by} = defined $_[1] ? $_[1] : 1; | ||||
| 228 | $_[0]; | ||||
| 229 | } | ||||
| 230 | |||||
| 231 | sub allow_bigint { | ||||
| 232 | Carp::carp("allow_bigint() is obsoleted. use allow_bignum() insted."); | ||||
| 233 | } | ||||
| 234 | |||||
| 235 | ############################### | ||||
| 236 | |||||
| 237 | ### | ||||
| 238 | ### Perl => JSON | ||||
| 239 | ### | ||||
| 240 | |||||
| 241 | |||||
| 242 | { # Convert | ||||
| 243 | |||||
| 244 | 2 | 0s | my $max_depth; | ||
| 245 | my $indent; | ||||
| 246 | my $ascii; | ||||
| 247 | my $latin1; | ||||
| 248 | my $utf8; | ||||
| 249 | my $space_before; | ||||
| 250 | my $space_after; | ||||
| 251 | my $canonical; | ||||
| 252 | my $allow_blessed; | ||||
| 253 | my $convert_blessed; | ||||
| 254 | |||||
| 255 | my $indent_length; | ||||
| 256 | my $escape_slash; | ||||
| 257 | my $bignum; | ||||
| 258 | my $as_nonblessed; | ||||
| 259 | |||||
| 260 | my $depth; | ||||
| 261 | my $indent_count; | ||||
| 262 | my $keysort; | ||||
| 263 | |||||
| 264 | |||||
| 265 | # spent 93.6ms (0s+93.6) within JSON::PP::PP_encode_json which was called 63 times, avg 1.49ms/call:
# 63 times (0s+93.6ms) by JSON::PP::encode at line 143, avg 1.49ms/call  | ||||
| 266 | 63 | 0s | my $self = shift; | ||
| 267 | 63 | 0s | my $obj = shift; | ||
| 268 | |||||
| 269 | 63 | 0s | $indent_count = 0; | ||
| 270 | 63 | 0s | $depth = 0; | ||
| 271 | |||||
| 272 | 63 | 0s | my $idx = $self->{PROPS}; | ||
| 273 | |||||
| 274 | ($ascii, $latin1, $utf8, $indent, $canonical, $space_before, $space_after, $allow_blessed, | ||||
| 275 | $convert_blessed, $escape_slash, $bignum, $as_nonblessed) | ||||
| 276 | 63 | 0s | = @{$idx}[P_ASCII .. P_SPACE_AFTER, P_ALLOW_BLESSED, P_CONVERT_BLESSED, | ||
| 277 | P_ESCAPE_SLASH, P_ALLOW_BIGNUM, P_AS_NONBLESSED]; | ||||
| 278 | |||||
| 279 | 63 | 0s | ($max_depth, $indent_length) = @{$self}{qw/max_depth indent_length/}; | ||
| 280 | |||||
| 281 | 367 | 0s | $keysort = $canonical ? sub { $a cmp $b } : undef; | ||
| 282 | |||||
| 283 | 63 | 0s | if ($self->{sort_by}) { | ||
| 284 | $keysort = ref($self->{sort_by}) eq 'CODE' ? $self->{sort_by} | ||||
| 285 | : $self->{sort_by} =~ /\D+/ ? $self->{sort_by} | ||||
| 286 | : sub { $a cmp $b }; | ||||
| 287 | } | ||||
| 288 | |||||
| 289 | 63 | 0s | encode_error("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)") | ||
| 290 | if(!ref $obj and !$idx->[ P_ALLOW_NONREF ]); | ||||
| 291 | |||||
| 292 | 63 | 0s | 63 | 93.6ms |         my $str  = $self->object_to_json($obj);         # spent  93.6ms making 63 calls to JSON::PP::object_to_json, avg 1.49ms/call  | 
| 293 | |||||
| 294 | 63 | 0s | $str .= "\n" if ( $indent ); # JSON::XS 2.26 compatible | ||
| 295 | |||||
| 296 | 63 | 0s | 9 | 0s |         unless ($ascii or $latin1 or $utf8) {         # spent     0s making 9 calls to utf8::upgrade, avg 0s/call  | 
| 297 | utf8::upgrade($str); | ||||
| 298 | } | ||||
| 299 | |||||
| 300 | 63 | 0s | if ($idx->[ P_SHRINK ]) { | ||
| 301 | utf8::downgrade($str, 1); | ||||
| 302 | } | ||||
| 303 | |||||
| 304 | 63 | 0s | return $str; | ||
| 305 | } | ||||
| 306 | |||||
| 307 | |||||
| 308 | # spent 93.6ms (15.6+78.0) within JSON::PP::object_to_json which was called 1321 times, avg 71µs/call:
# 1068 times (15.6ms+-15.6ms) by JSON::PP::hash_to_json at line 368, avg 0s/call
#  171 times (0s+0s) by JSON::PP::array_to_json at line 390, avg 0s/call
#   63 times (0s+93.6ms) by JSON::PP::PP_encode_json at line 292, avg 1.49ms/call
#   19 times (0s+0s) by JSON::PP::object_to_json at line 334, avg 0s/call  | ||||
| 309 | 1321 | 0s | my ($self, $obj) = @_; | ||
| 310 | 1321 | 0s | my $type = ref($obj); | ||
| 311 | |||||
| 312 | 1321 | 0s | 595 | 109ms |         if($type eq 'HASH'){         # spent   109ms making 465 calls to JSON::PP::hash_to_json, avg 235µs/call, recursion: max depth 3, sum of overlapping time 15.6ms
        # spent  15.6ms making 130 calls to JSON::PP::array_to_json, avg 120µs/call  | 
| 313 | return $self->hash_to_json($obj); | ||||
| 314 | } | ||||
| 315 | elsif($type eq 'ARRAY'){ | ||||
| 316 | return $self->array_to_json($obj); | ||||
| 317 | } | ||||
| 318 | elsif ($type) { # blessed object? | ||||
| 319 | 19 | 0s | 19 | 0s |             if (blessed($obj)) {             # spent     0s making 19 calls to Scalar::Util::blessed, avg 0s/call  | 
| 320 | |||||
| 321 | 19 | 0s | 19 | 0s |                 return $self->value_to_json($obj) if ( $obj->isa('JSON::PP::Boolean') );                 # spent     0s making 19 calls to UNIVERSAL::isa, avg 0s/call  | 
| 322 | |||||
| 323 | 19 | 0s | 19 | 0s |                 if ( $convert_blessed and $obj->can('TO_JSON') ) {                 # spent     0s making 19 calls to UNIVERSAL::can, avg 0s/call  | 
| 324 | 19 | 0s | 19 | 0s |                     my $result = $obj->TO_JSON();                     # spent     0s making 19 calls to CPAN::Meta::TO_JSON, avg 0s/call  | 
| 325 | 19 | 0s | 38 | 0s |                     if ( defined $result and ref( $result ) ) {                     # spent     0s making 38 calls to Scalar::Util::refaddr, avg 0s/call  | 
| 326 | if ( refaddr( $obj ) eq refaddr( $result ) ) { | ||||
| 327 | encode_error( sprintf( | ||||
| 328 | "%s::TO_JSON method returned same object as was passed instead of a new one", | ||||
| 329 | ref $obj | ||||
| 330 | ) ); | ||||
| 331 | } | ||||
| 332 | } | ||||
| 333 | |||||
| 334 | 19 | 0s | 19 | 0s |                     return $self->object_to_json( $result );                     # spent  31.2ms making 19 calls to JSON::PP::object_to_json, avg 1.64ms/call, recursion: max depth 1, sum of overlapping time 31.2ms  | 
| 335 | } | ||||
| 336 | |||||
| 337 | return "$obj" if ( $bignum and _is_bignum($obj) ); | ||||
| 338 | return $self->blessed_to_json($obj) if ($allow_blessed and $as_nonblessed); # will be removed. | ||||
| 339 | |||||
| 340 | encode_error( sprintf("encountered object '%s', but neither allow_blessed " | ||||
| 341 | . "nor convert_blessed settings are enabled", $obj) | ||||
| 342 | ) unless ($allow_blessed); | ||||
| 343 | |||||
| 344 | return 'null'; | ||||
| 345 | } | ||||
| 346 | else { | ||||
| 347 | return $self->value_to_json($obj); | ||||
| 348 | } | ||||
| 349 | } | ||||
| 350 | else{ | ||||
| 351 | 707 | 15.6ms | 707 | 46.8ms |             return $self->value_to_json($obj);             # spent  46.8ms making 707 calls to JSON::PP::value_to_json, avg 66µs/call  | 
| 352 | } | ||||
| 353 | } | ||||
| 354 | |||||
| 355 | |||||
| 356 | # spent 93.6ms (15.6+78.0) within JSON::PP::hash_to_json which was called 465 times, avg 201µs/call:
# 465 times (15.6ms+78.0ms) by JSON::PP::object_to_json at line 312, avg 201µs/call  | ||||
| 357 | 465 | 0s | my ($self, $obj) = @_; | ||
| 358 | 465 | 0s | my @res; | ||
| 359 | |||||
| 360 | 465 | 0s | encode_error("json text or perl structure exceeds maximum nesting level (max_depth set too low?)") | ||
| 361 | if (++$depth > $max_depth); | ||||
| 362 | |||||
| 363 | 465 | 0s | 96 | 0s |         my ($pre, $post) = $indent ? $self->_up_indent() : ('', '');         # spent     0s making 96 calls to JSON::PP::_up_indent, avg 0s/call  | 
| 364 | 465 | 0s | my $del = ($space_before ? ' ' : '') . ':' . ($space_after ? ' ' : ''); | ||
| 365 | |||||
| 366 | 465 | 0s | 465 | 0s |         for my $k ( _sort( $obj ) ) {         # spent     0s making 465 calls to JSON::PP::_sort, avg 0s/call  | 
| 367 | if ( OLD_PERL ) { utf8::decode($k) } # key for Perl 5.6 / be optimized | ||||
| 368 | 1068 | 0s | 2163 | 15.6ms |             push @res, string_to_json( $self, $k )             # spent  15.6ms making 1068 calls to JSON::PP::string_to_json, avg 15µs/call
            # spent  78.0ms making 1068 calls to JSON::PP::object_to_json, avg 73µs/call, recursion: max depth 5, sum of overlapping time 78.0ms
            # spent     0s making   27 calls to JSON::PP::value_to_json, avg 0s/call  | 
| 369 | . $del | ||||
| 370 | . ( $self->object_to_json( $obj->{$k} ) || $self->value_to_json( $obj->{$k} ) ); | ||||
| 371 | } | ||||
| 372 | |||||
| 373 | 465 | 0s | --$depth; | ||
| 374 | 465 | 0s | 96 | 0s |         $self->_down_indent() if ($indent);         # spent     0s making 96 calls to JSON::PP::_down_indent, avg 0s/call  | 
| 375 | |||||
| 376 | 465 | 0s | return '{' . ( @res ? $pre : '' ) . ( @res ? join( ",$pre", @res ) . $post : '' ) . '}'; | ||
| 377 | } | ||||
| 378 | |||||
| 379 | |||||
| 380 | # spent 15.6ms (0s+15.6) within JSON::PP::array_to_json which was called 130 times, avg 120µs/call:
# 130 times (0s+15.6ms) by JSON::PP::object_to_json at line 312, avg 120µs/call  | ||||
| 381 | 130 | 0s | my ($self, $obj) = @_; | ||
| 382 | 130 | 0s | my @res; | ||
| 383 | |||||
| 384 | 130 | 0s | encode_error("json text or perl structure exceeds maximum nesting level (max_depth set too low?)") | ||
| 385 | if (++$depth > $max_depth); | ||||
| 386 | |||||
| 387 | 130 | 0s | 27 | 0s |         my ($pre, $post) = $indent ? $self->_up_indent() : ('', '');         # spent     0s making 27 calls to JSON::PP::_up_indent, avg 0s/call  | 
| 388 | |||||
| 389 | 130 | 0s | for my $v (@$obj){ | ||
| 390 | 171 | 0s | 171 | 0s |             push @res, $self->object_to_json($v) || $self->value_to_json($v);             # spent  15.6ms making 171 calls to JSON::PP::object_to_json, avg 91µs/call, recursion: max depth 4, sum of overlapping time 15.6ms  | 
| 391 | } | ||||
| 392 | |||||
| 393 | 130 | 0s | --$depth; | ||
| 394 | 130 | 0s | 27 | 0s |         $self->_down_indent() if ($indent);         # spent     0s making 27 calls to JSON::PP::_down_indent, avg 0s/call  | 
| 395 | |||||
| 396 | 130 | 15.6ms | return '[' . ( @res ? $pre : '' ) . ( @res ? join( ",$pre", @res ) . $post : '' ) . ']'; | ||
| 397 | } | ||||
| 398 | |||||
| 399 | |||||
| 400 | sub value_to_json { | ||||
| 401 | 734 | 0s | my ($self, $value) = @_; | ||
| 402 | |||||
| 403 | 734 | 0s | return 'null' if(!defined $value); | ||
| 404 | |||||
| 405 | 734 | 0s | 734 | 0s |         my $b_obj = B::svref_2object(\$value);  # for round trip problem         # spent     0s making 734 calls to B::svref_2object, avg 0s/call  | 
| 406 | 734 | 15.6ms | 734 | 0s |         my $flags = $b_obj->FLAGS;         # spent     0s making 734 calls to B::SV::FLAGS, avg 0s/call  | 
| 407 | |||||
| 408 | 734 | 15.6ms | return $value # as is | ||
| 409 | if $flags & ( B::SVp_IOK | B::SVp_NOK ) and !( $flags & B::SVp_POK ); # SvTYPE is IV or NV? | ||||
| 410 | |||||
| 411 | 645 | 0s | my $type = ref($value); | ||
| 412 | |||||
| 413 | 645 | 0s | 645 | 15.6ms |         if(!$type){         # spent  15.6ms making 645 calls to JSON::PP::string_to_json, avg 24µs/call  | 
| 414 | return string_to_json($self, $value); | ||||
| 415 | } | ||||
| 416 | elsif( blessed($value) and $value->isa('JSON::PP::Boolean') ){ | ||||
| 417 | return $$value == 1 ? 'true' : 'false'; | ||||
| 418 | } | ||||
| 419 | elsif ($type) { | ||||
| 420 | if ((overload::StrVal($value) =~ /=(\w+)/)[0]) { | ||||
| 421 | return $self->value_to_json("$value"); | ||||
| 422 | } | ||||
| 423 | |||||
| 424 | if ($type eq 'SCALAR' and defined $$value) { | ||||
| 425 | return $$value eq '1' ? 'true' | ||||
| 426 | : $$value eq '0' ? 'false' | ||||
| 427 | : $self->{PROPS}->[ P_ALLOW_UNKNOWN ] ? 'null' | ||||
| 428 | : encode_error("cannot encode reference to scalar"); | ||||
| 429 | } | ||||
| 430 | |||||
| 431 | if ( $self->{PROPS}->[ P_ALLOW_UNKNOWN ] ) { | ||||
| 432 | return 'null'; | ||||
| 433 | } | ||||
| 434 | else { | ||||
| 435 | if ( $type eq 'SCALAR' or $type eq 'REF' ) { | ||||
| 436 | encode_error("cannot encode reference to scalar"); | ||||
| 437 | } | ||||
| 438 | else { | ||||
| 439 | encode_error("encountered $value, but JSON can only represent references to arrays or hashes"); | ||||
| 440 | } | ||||
| 441 | } | ||||
| 442 | |||||
| 443 | } | ||||
| 444 | else { | ||||
| 445 | return $self->{fallback}->($value) | ||||
| 446 | if ($self->{fallback} and ref($self->{fallback}) eq 'CODE'); | ||||
| 447 | return 'null'; | ||||
| 448 | } | ||||
| 449 | |||||
| 450 | } | ||||
| 451 | |||||
| 452 | |||||
| 453 | 1 | 0s | my %esc = ( | ||
| 454 | "\n" => '\n', | ||||
| 455 | "\r" => '\r', | ||||
| 456 | "\t" => '\t', | ||||
| 457 | "\f" => '\f', | ||||
| 458 | "\b" => '\b', | ||||
| 459 | "\"" => '\"', | ||||
| 460 | "\\" => '\\\\', | ||||
| 461 | "\'" => '\\\'', | ||||
| 462 | ); | ||||
| 463 | |||||
| 464 | |||||
| 465 | sub string_to_json { | ||||
| 466 | 1713 | 0s | my ($self, $arg) = @_; | ||
| 467 | |||||
| 468 | 1713 | 31.2ms | 1713 | 15.6ms |         $arg =~ s/([\x22\x5c\n\r\t\f\b])/$esc{$1}/g;         # spent  15.6ms making 1713 calls to JSON::PP::CORE:subst, avg 9µs/call  | 
| 469 | 1713 | 0s | $arg =~ s/\//\\\//g if ($escape_slash); | ||
| 470 | 1713 | 0s | 1713 | 0s |         $arg =~ s/([\x00-\x08\x0b\x0e-\x1f])/'\\u00' . unpack('H2', $1)/eg;         # spent     0s making 1713 calls to JSON::PP::CORE:subst, avg 0s/call  | 
| 471 | |||||
| 472 | 1713 | 0s | if ($ascii) { | ||
| 473 | $arg = JSON_PP_encode_ascii($arg); | ||||
| 474 | } | ||||
| 475 | |||||
| 476 | 1713 | 0s | if ($latin1) { | ||
| 477 | $arg = JSON_PP_encode_latin1($arg); | ||||
| 478 | } | ||||
| 479 | |||||
| 480 | 1713 | 0s | 1374 | 0s |         if ($utf8) {         # spent     0s making 1374 calls to utf8::encode, avg 0s/call  | 
| 481 | utf8::encode($arg); | ||||
| 482 | } | ||||
| 483 | |||||
| 484 | 1713 | 0s | return '"' . $arg . '"'; | ||
| 485 | } | ||||
| 486 | |||||
| 487 | |||||
| 488 | sub blessed_to_json { | ||||
| 489 | my $reftype = reftype($_[1]) || ''; | ||||
| 490 | if ($reftype eq 'HASH') { | ||||
| 491 | return $_[0]->hash_to_json($_[1]); | ||||
| 492 | } | ||||
| 493 | elsif ($reftype eq 'ARRAY') { | ||||
| 494 | return $_[0]->array_to_json($_[1]); | ||||
| 495 | } | ||||
| 496 | else { | ||||
| 497 | return 'null'; | ||||
| 498 | } | ||||
| 499 | } | ||||
| 500 | |||||
| 501 | |||||
| 502 | sub encode_error { | ||||
| 503 | my $error = shift; | ||||
| 504 | Carp::croak "$error"; | ||||
| 505 | } | ||||
| 506 | |||||
| 507 | |||||
| 508 | # spent 0s within JSON::PP::_sort which was called 465 times, avg 0s/call:
# 465 times (0s+0s) by JSON::PP::hash_to_json at line 366, avg 0s/call  | ||||
| 509 | 465 | 0s | 96 | 0s |         defined $keysort ? (sort $keysort (keys %{$_[0]})) : keys %{$_[0]};         # spent     0s making 96 calls to JSON::PP::CORE:sort, avg 0s/call  | 
| 510 | } | ||||
| 511 | |||||
| 512 | |||||
| 513 | sub _up_indent { | ||||
| 514 | 123 | 0s | my $self = shift; | ||
| 515 | 123 | 0s | my $space = ' ' x $indent_length; | ||
| 516 | |||||
| 517 | 123 | 0s | my ($pre,$post) = ('',''); | ||
| 518 | |||||
| 519 | 123 | 0s | $post = "\n" . $space x $indent_count; | ||
| 520 | |||||
| 521 | 123 | 0s | $indent_count++; | ||
| 522 | |||||
| 523 | 123 | 0s | $pre = "\n" . $space x $indent_count; | ||
| 524 | |||||
| 525 | 123 | 0s | return ($pre,$post); | ||
| 526 | } | ||||
| 527 | |||||
| 528 | |||||
| 529 | 123 | 0s | sub _down_indent { $indent_count--; } | ||
| 530 | |||||
| 531 | |||||
| 532 | sub PP_encode_box { | ||||
| 533 | { | ||||
| 534 | depth => $depth, | ||||
| 535 | indent_count => $indent_count, | ||||
| 536 | }; | ||||
| 537 | } | ||||
| 538 | |||||
| 539 | } # Convert | ||||
| 540 | |||||
| 541 | |||||
| 542 | sub _encode_ascii { | ||||
| 543 | join('', | ||||
| 544 | map { | ||||
| 545 | $_ <= 127 ? | ||||
| 546 | chr($_) : | ||||
| 547 | $_ <= 65535 ? | ||||
| 548 | sprintf('\u%04x', $_) : sprintf('\u%x\u%x', _encode_surrogates($_)); | ||||
| 549 | } unpack('U*', $_[0]) | ||||
| 550 | ); | ||||
| 551 | } | ||||
| 552 | |||||
| 553 | |||||
| 554 | sub _encode_latin1 { | ||||
| 555 | join('', | ||||
| 556 | map { | ||||
| 557 | $_ <= 255 ? | ||||
| 558 | chr($_) : | ||||
| 559 | $_ <= 65535 ? | ||||
| 560 | sprintf('\u%04x', $_) : sprintf('\u%x\u%x', _encode_surrogates($_)); | ||||
| 561 | } unpack('U*', $_[0]) | ||||
| 562 | ); | ||||
| 563 | } | ||||
| 564 | |||||
| 565 | |||||
| 566 | sub _encode_surrogates { # from perlunicode | ||||
| 567 | my $uni = $_[0] - 0x10000; | ||||
| 568 | return ($uni / 0x400 + 0xD800, $uni % 0x400 + 0xDC00); | ||||
| 569 | } | ||||
| 570 | |||||
| 571 | |||||
| 572 | sub _is_bignum { | ||||
| 573 | $_[0]->isa('Math::BigInt') or $_[0]->isa('Math::BigFloat'); | ||||
| 574 | } | ||||
| 575 | |||||
| - - | |||||
| 578 | # | ||||
| 579 | # JSON => Perl | ||||
| 580 | # | ||||
| 581 | |||||
| 582 | 1 | 0s | my $max_intsize; | ||
| 583 | |||||
| 584 | # spent 0s within JSON::PP::BEGIN@584 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 594  | ||||
| 585 | 1 | 0s | my $checkint = 1111; | ||
| 586 | 1 | 0s | for my $d (5..64) { | ||
| 587 | 17 | 0s | $checkint .= 1; | ||
| 588 | 17 | 0s |         my $int   = eval qq| $checkint |;         # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval
        # spent     0s executing statements in string eval  | ||
| 589 | 17 | 0s | 17 | 0s |         if ($int =~ /[eE]/) {         # spent     0s making 17 calls to JSON::PP::CORE:match, avg 0s/call  | 
| 590 | 1 | 0s | $max_intsize = $d - 1; | ||
| 591 | 1 | 0s | last; | ||
| 592 | } | ||||
| 593 | } | ||||
| 594 | 1 | 0s | 1 | 0s | } # spent     0s making 1 call to JSON::PP::BEGIN@584  | 
| 595 | |||||
| 596 | { # PARSE | ||||
| 597 | |||||
| 598 | 2 | 0s | my %escapes = ( # by Jeremy Muhlich <jmuhlich [at] bitflood.org> | ||
| 599 | b => "\x8", | ||||
| 600 | t => "\x9", | ||||
| 601 | n => "\xA", | ||||
| 602 | f => "\xC", | ||||
| 603 | r => "\xD", | ||||
| 604 | '\\' => '\\', | ||||
| 605 | '"' => '"', | ||||
| 606 | '/' => '/', | ||||
| 607 | ); | ||||
| 608 | |||||
| 609 | 1 | 0s | my $text; # json data | ||
| 610 | my $at; # offset | ||||
| 611 | my $ch; # 1chracter | ||||
| 612 | my $len; # text length (changed according to UTF8 or NON UTF8) | ||||
| 613 | # INTERNAL | ||||
| 614 | my $depth; # nest counter | ||||
| 615 | my $encoding; # json text encoding | ||||
| 616 | my $is_valid_utf8; # temp variable | ||||
| 617 | my $utf8_len; # utf8 byte length | ||||
| 618 | # FLAGS | ||||
| 619 | my $utf8; # must be utf8 | ||||
| 620 | my $max_depth; # max nest nubmer of objects and arrays | ||||
| 621 | my $max_size; | ||||
| 622 | my $relaxed; | ||||
| 623 | my $cb_object; | ||||
| 624 | my $cb_sk_object; | ||||
| 625 | |||||
| 626 | my $F_HOOK; | ||||
| 627 | |||||
| 628 | my $allow_bigint; # using Math::BigInt | ||||
| 629 | my $singlequote; # loosely quoting | ||||
| 630 | my $loose; # | ||||
| 631 | 1 | 0s | my $allow_barekey; # bareKey | ||
| 632 | |||||
| 633 | # $opt flag | ||||
| 634 | # 0x00000001 .... decode_prefix | ||||
| 635 | # 0x10000000 .... incr_parse | ||||
| 636 | |||||
| 637 | # spent 109ms (0s+109) within JSON::PP::PP_decode_json which was called 55 times, avg 1.99ms/call:
# 55 times (0s+109ms) by JSON::PP::decode at line 148, avg 1.99ms/call  | ||||
| 638 | 55 | 0s | my ($self, $opt); # $opt is an effective flag during this decode_json. | ||
| 639 | |||||
| 640 | 55 | 0s | ($self, $text, $opt) = @_; | ||
| 641 | |||||
| 642 | 55 | 0s | ($at, $ch, $depth) = (0, '', 0); | ||
| 643 | |||||
| 644 | 55 | 0s | if ( !defined $text or ref $text ) { | ||
| 645 | decode_error("malformed JSON string, neither array, object, number, string or atom"); | ||||
| 646 | } | ||||
| 647 | |||||
| 648 | 55 | 0s | my $idx = $self->{PROPS}; | ||
| 649 | |||||
| 650 | ($utf8, $relaxed, $loose, $allow_bigint, $allow_barekey, $singlequote) | ||||
| 651 | 55 | 0s | = @{$idx}[P_UTF8, P_RELAXED, P_LOOSE .. P_ALLOW_SINGLEQUOTE]; | ||
| 652 | |||||
| 653 | 55 | 0s | 54 | 0s |         if ( $utf8 ) {         # spent     0s making 54 calls to utf8::downgrade, avg 0s/call  | 
| 654 | utf8::downgrade( $text, 1 ) or Carp::croak("Wide character in subroutine entry"); | ||||
| 655 | } | ||||
| 656 | else { | ||||
| 657 | 1 | 0s | 1 | 0s |             utf8::upgrade( $text );             # spent     0s making 1 call to utf8::upgrade  | 
| 658 | 1 | 0s | 1 | 0s |             utf8::encode( $text );             # spent     0s making 1 call to utf8::encode  | 
| 659 | } | ||||
| 660 | |||||
| 661 | 55 | 0s | $len = length $text; | ||
| 662 | |||||
| 663 | ($max_depth, $max_size, $cb_object, $cb_sk_object, $F_HOOK) | ||||
| 664 | 55 | 0s | = @{$self}{qw/max_depth max_size cb_object cb_sk_object F_HOOK/}; | ||
| 665 | |||||
| 666 | 55 | 0s | if ($max_size > 1) { | ||
| 667 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::BEGIN@667 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 667             # spent     0s making 1 call to JSON::PP::BEGIN@667
            # spent     0s making 1 call to bytes::import  | 
| 668 | my $bytes = length $text; | ||||
| 669 | decode_error( | ||||
| 670 | sprintf("attempted decode of JSON text of %s bytes size, but max_size is set to %s" | ||||
| 671 | , $bytes, $max_size), 1 | ||||
| 672 | ) if ($bytes > $max_size); | ||||
| 673 | } | ||||
| 674 | |||||
| 675 | # Currently no effect | ||||
| 676 | # should use regexp | ||||
| 677 | 55 | 0s | 55 | 0s |         my @octets = unpack('C4', $text);         # spent     0s making 55 calls to JSON::PP::CORE:unpack, avg 0s/call  | 
| 678 | 55 | 0s | $encoding = ( $octets[0] and $octets[1]) ? 'UTF-8' | ||
| 679 | : (!$octets[0] and $octets[1]) ? 'UTF-16BE' | ||||
| 680 | : (!$octets[0] and !$octets[1]) ? 'UTF-32BE' | ||||
| 681 | : ( $octets[2] ) ? 'UTF-16LE' | ||||
| 682 | : (!$octets[2] ) ? 'UTF-32LE' | ||||
| 683 | : 'unknown'; | ||||
| 684 | |||||
| 685 | 55 | 0s | 55 | 0s |         white(); # remove head white space         # spent     0s making 55 calls to JSON::PP::white, avg 0s/call  | 
| 686 | |||||
| 687 | 55 | 0s | my $valid_start = defined $ch; # Is there a first character for JSON structure? | ||
| 688 | |||||
| 689 | 55 | 0s | 55 | 109ms |         my $result = value();         # spent   109ms making 55 calls to JSON::PP::value, avg 1.99ms/call  | 
| 690 | |||||
| 691 | 55 | 0s | return undef if ( !$result && ( $opt & 0x10000000 ) ); # for incr_parse | ||
| 692 | |||||
| 693 | 55 | 0s | decode_error("malformed JSON string, neither array, object, number, string or atom") unless $valid_start; | ||
| 694 | |||||
| 695 | 55 | 0s | if ( !$idx->[ P_ALLOW_NONREF ] and !ref $result ) { | ||
| 696 | decode_error( | ||||
| 697 | 'JSON text must be an object or array (but found number, string, true, false or null,' | ||||
| 698 | . ' use allow_nonref to allow this)', 1); | ||||
| 699 | } | ||||
| 700 | |||||
| 701 | 55 | 0s | Carp::croak('something wrong.') if $len < $at; # we won't arrive here. | ||
| 702 | |||||
| 703 | 55 | 0s | my $consumed = defined $ch ? $at - 1 : $at; # consumed JSON text length | ||
| 704 | |||||
| 705 | 55 | 0s | 55 | 0s |         white(); # remove tail white space         # spent     0s making 55 calls to JSON::PP::white, avg 0s/call  | 
| 706 | |||||
| 707 | 55 | 0s | if ( $ch ) { | ||
| 708 | return ( $result, $consumed ) if ($opt & 0x00000001); # all right if decode_prefix | ||||
| 709 | decode_error("garbage after JSON object"); | ||||
| 710 | } | ||||
| 711 | |||||
| 712 | 55 | 0s | ( $opt & 0x00000001 ) ? ( $result, $consumed ) : $result; | ||
| 713 | } | ||||
| 714 | |||||
| 715 | |||||
| 716 | # spent 46.8ms within JSON::PP::next_chr which was called 22642 times, avg 2µs/call:
# 17072 times (15.6ms+0s) by JSON::PP::string at line 746, avg 914ns/call
#  1406 times (15.6ms+0s) by JSON::PP::string at line 744, avg 11µs/call
#  1406 times (15.6ms+0s) by JSON::PP::string at line 747, avg 11µs/call
#   873 times (0s+0s) by JSON::PP::object at line 964, avg 0s/call
#   532 times (0s+0s) by JSON::PP::object at line 983, avg 0s/call
#   374 times (0s+0s) by JSON::PP::object at line 943, avg 0s/call
#   341 times (0s+0s) by JSON::PP::object at line 972, avg 0s/call
#   294 times (0s+0s) by JSON::PP::white at line 839, avg 0s/call
#   106 times (0s+0s) by JSON::PP::array at line 893, avg 0s/call
#   102 times (0s+0s) by JSON::PP::array at line 913, avg 0s/call
#    54 times (0s+0s) by JSON::PP::number at line 1085, avg 0s/call
#    37 times (0s+0s) by JSON::PP::array at line 921, avg 0s/call
#    33 times (0s+0s) by JSON::PP::object at line 948, avg 0s/call
#     4 times (0s+0s) by JSON::PP::number at line 1099, avg 0s/call
#     4 times (0s+0s) by JSON::PP::number at line 1091, avg 0s/call
#     4 times (0s+0s) by JSON::PP::array at line 898, avg 0s/call  | ||||
| 717 | 22642 | 15.6ms | return $ch = undef if($at >= $len); | ||
| 718 | 22587 | 31.2ms | $ch = substr($text, $at++, 1); | ||
| 719 | } | ||||
| 720 | |||||
| 721 | |||||
| 722 | # spent 109ms (15.6+93.6) within JSON::PP::value which was called 1067 times, avg 102µs/call:
# 873 times (15.6ms+-15.6ms) by JSON::PP::object at line 965, avg 0s/call
# 139 times (0s+0s) by JSON::PP::array at line 903, avg 0s/call
#  55 times (0s+109ms) by JSON::PP::PP_decode_json at line 689, avg 1.99ms/call  | ||||
| 723 | 1067 | 0s | 1067 | 0s |         white();         # spent     0s making 1067 calls to JSON::PP::white, avg 0s/call  | 
| 724 | 1067 | 0s | return if(!defined $ch); | ||
| 725 | 1067 | 0s | 374 | 109ms |         return object() if($ch eq '{');         # spent   125ms making 374 calls to JSON::PP::object, avg 334µs/call, recursion: max depth 3, sum of overlapping time 15.6ms  | 
| 726 | 693 | 0s | 106 | 0s |         return array()  if($ch eq '[');         # spent     0s making 106 calls to JSON::PP::array, avg 0s/call  | 
| 727 | 587 | 15.6ms | 533 | 31.2ms |         return string() if($ch eq '"' or ($singlequote and $ch eq "'"));         # spent  31.2ms making 533 calls to JSON::PP::string, avg 59µs/call  | 
| 728 | 54 | 0s | 108 | 0s |         return number() if($ch =~ /[0-9]/ or $ch eq '-');         # spent     0s making 54 calls to JSON::PP::CORE:match, avg 0s/call
        # spent     0s making 54 calls to JSON::PP::number, avg 0s/call  | 
| 729 | return word(); | ||||
| 730 | } | ||||
| 731 | |||||
| 732 | sub string { | ||||
| 733 | 1406 | 0s | my ($i, $s, $t, $u); | ||
| 734 | my $utf16; | ||||
| 735 | my $is_utf8; | ||||
| 736 | |||||
| 737 | 1406 | 0s | ($is_valid_utf8, $utf8_len) = ('', 0); | ||
| 738 | |||||
| 739 | 1406 | 0s | $s = ''; # basically UTF8 flag on | ||
| 740 | |||||
| 741 | 1406 | 0s | if($ch eq '"' or ($singlequote and $ch eq "'")){ | ||
| 742 | 1406 | 0s | my $boundChar = $ch; | ||
| 743 | |||||
| 744 | 1406 | 0s | 1406 | 15.6ms |             OUTER: while( defined(next_chr()) ){             # spent  15.6ms making 1406 calls to JSON::PP::next_chr, avg 11µs/call  | 
| 745 | |||||
| 746 | 18478 | 31.2ms | 17072 | 15.6ms |                 if($ch eq $boundChar){                 # spent  15.6ms making 17072 calls to JSON::PP::next_chr, avg 914ns/call  | 
| 747 | 1406 | 0s | 1406 | 15.6ms |                     next_chr();                     # spent  15.6ms making 1406 calls to JSON::PP::next_chr, avg 11µs/call  | 
| 748 | |||||
| 749 | 1406 | 0s | if ($utf16) { | ||
| 750 | decode_error("missing low surrogate character in surrogate pair"); | ||||
| 751 | } | ||||
| 752 | |||||
| 753 | 1406 | 0s | utf8::decode($s) if($is_utf8); | ||
| 754 | |||||
| 755 | 1406 | 0s | return $s; | ||
| 756 | } | ||||
| 757 | elsif($ch eq '\\'){ | ||||
| 758 | next_chr(); | ||||
| 759 | if(exists $escapes{$ch}){ | ||||
| 760 | $s .= $escapes{$ch}; | ||||
| 761 | } | ||||
| 762 | elsif($ch eq 'u'){ # UNICODE handling | ||||
| 763 | my $u = ''; | ||||
| 764 | |||||
| 765 | for(1..4){ | ||||
| 766 | $ch = next_chr(); | ||||
| 767 | last OUTER if($ch !~ /[0-9a-fA-F]/); | ||||
| 768 | $u .= $ch; | ||||
| 769 | } | ||||
| 770 | |||||
| 771 | # U+D800 - U+DBFF | ||||
| 772 | if ($u =~ /^[dD][89abAB][0-9a-fA-F]{2}/) { # UTF-16 high surrogate? | ||||
| 773 | $utf16 = $u; | ||||
| 774 | } | ||||
| 775 | # U+DC00 - U+DFFF | ||||
| 776 | elsif ($u =~ /^[dD][c-fC-F][0-9a-fA-F]{2}/) { # UTF-16 low surrogate? | ||||
| 777 | unless (defined $utf16) { | ||||
| 778 | decode_error("missing high surrogate character in surrogate pair"); | ||||
| 779 | } | ||||
| 780 | $is_utf8 = 1; | ||||
| 781 | $s .= JSON_PP_decode_surrogates($utf16, $u) || next; | ||||
| 782 | $utf16 = undef; | ||||
| 783 | } | ||||
| 784 | else { | ||||
| 785 | if (defined $utf16) { | ||||
| 786 | decode_error("surrogate pair expected"); | ||||
| 787 | } | ||||
| 788 | |||||
| 789 | if ( ( my $hex = hex( $u ) ) > 127 ) { | ||||
| 790 | $is_utf8 = 1; | ||||
| 791 | $s .= JSON_PP_decode_unicode($u) || next; | ||||
| 792 | } | ||||
| 793 | else { | ||||
| 794 | $s .= chr $hex; | ||||
| 795 | } | ||||
| 796 | } | ||||
| 797 | |||||
| 798 | } | ||||
| 799 | else{ | ||||
| 800 | unless ($loose) { | ||||
| 801 | $at -= 2; | ||||
| 802 | decode_error('illegal backslash escape sequence in string'); | ||||
| 803 | } | ||||
| 804 | $s .= $ch; | ||||
| 805 | } | ||||
| 806 | } | ||||
| 807 | else{ | ||||
| 808 | |||||
| 809 | 17072 | 0s | if ( ord $ch > 127 ) { | ||
| 810 | unless( $ch = is_valid_utf8($ch) ) { | ||||
| 811 | $at -= 1; | ||||
| 812 | decode_error("malformed UTF-8 character in JSON string"); | ||||
| 813 | } | ||||
| 814 | else { | ||||
| 815 | $at += $utf8_len - 1; | ||||
| 816 | } | ||||
| 817 | |||||
| 818 | $is_utf8 = 1; | ||||
| 819 | } | ||||
| 820 | |||||
| 821 | 17072 | 0s | if (!$loose) { | ||
| 822 | 17072 | 0s | 17072 | 0s |                         if ($ch =~ /[\x00-\x1f\x22\x5c]/)  { # '/' ok                         # spent     0s making 17072 calls to JSON::PP::CORE:match, avg 0s/call  | 
| 823 | $at--; | ||||
| 824 | decode_error('invalid character encountered while parsing JSON string'); | ||||
| 825 | } | ||||
| 826 | } | ||||
| 827 | |||||
| 828 | 17072 | 0s | $s .= $ch; | ||
| 829 | } | ||||
| 830 | } | ||||
| 831 | } | ||||
| 832 | |||||
| 833 | decode_error("unexpected end of string while parsing JSON string"); | ||||
| 834 | } | ||||
| 835 | |||||
| 836 | |||||
| 837 | # spent 0s within JSON::PP::white which was called 4111 times, avg 0s/call:
# 1067 times (0s+0s) by JSON::PP::value at line 723, avg 0s/call
#  873 times (0s+0s) by JSON::PP::object at line 966, avg 0s/call
#  873 times (0s+0s) by JSON::PP::object at line 957, avg 0s/call
#  532 times (0s+0s) by JSON::PP::object at line 984, avg 0s/call
#  374 times (0s+0s) by JSON::PP::object at line 944, avg 0s/call
#  139 times (0s+0s) by JSON::PP::array at line 905, avg 0s/call
#  106 times (0s+0s) by JSON::PP::array at line 894, avg 0s/call
#   55 times (0s+0s) by JSON::PP::PP_decode_json at line 705, avg 0s/call
#   55 times (0s+0s) by JSON::PP::PP_decode_json at line 685, avg 0s/call
#   37 times (0s+0s) by JSON::PP::array at line 922, avg 0s/call  | ||||
| 838 | 4111 | 0s | while( defined $ch ){ | ||
| 839 | 4350 | 0s | 294 | 0s |             if($ch le ' '){             # spent     0s making 294 calls to JSON::PP::next_chr, avg 0s/call  | 
| 840 | next_chr(); | ||||
| 841 | } | ||||
| 842 | elsif($ch eq '/'){ | ||||
| 843 | next_chr(); | ||||
| 844 | if(defined $ch and $ch eq '/'){ | ||||
| 845 | 1 while(defined(next_chr()) and $ch ne "\n" and $ch ne "\r"); | ||||
| 846 | } | ||||
| 847 | elsif(defined $ch and $ch eq '*'){ | ||||
| 848 | next_chr(); | ||||
| 849 | while(1){ | ||||
| 850 | if(defined $ch){ | ||||
| 851 | if($ch eq '*'){ | ||||
| 852 | if(defined(next_chr()) and $ch eq '/'){ | ||||
| 853 | next_chr(); | ||||
| 854 | last; | ||||
| 855 | } | ||||
| 856 | } | ||||
| 857 | else{ | ||||
| 858 | next_chr(); | ||||
| 859 | } | ||||
| 860 | } | ||||
| 861 | else{ | ||||
| 862 | decode_error("Unterminated comment"); | ||||
| 863 | } | ||||
| 864 | } | ||||
| 865 | next; | ||||
| 866 | } | ||||
| 867 | else{ | ||||
| 868 | $at--; | ||||
| 869 | decode_error("malformed JSON string, neither array, object, number, string or atom"); | ||||
| 870 | } | ||||
| 871 | } | ||||
| 872 | else{ | ||||
| 873 | 4056 | 0s | if ($relaxed and $ch eq '#') { # correctly? | ||
| 874 | pos($text) = $at; | ||||
| 875 | $text =~ /\G([^\n]*(?:\r\n|\r|\n|$))/g; | ||||
| 876 | $at = pos($text); | ||||
| 877 | next_chr; | ||||
| 878 | next; | ||||
| 879 | } | ||||
| 880 | |||||
| 881 | 4056 | 15.6ms | last; | ||
| 882 | } | ||||
| 883 | } | ||||
| 884 | } | ||||
| 885 | |||||
| 886 | |||||
| 887 | # spent 0s within JSON::PP::array which was called 106 times, avg 0s/call:
# 106 times (0s+0s) by JSON::PP::value at line 726, avg 0s/call  | ||||
| 888 | 106 | 0s | my $a = $_[0] || []; # you can use this code to use another array ref object. | ||
| 889 | |||||
| 890 | 106 | 0s | decode_error('json text or perl structure exceeds maximum nesting level (max_depth set too low?)') | ||
| 891 | if (++$depth > $max_depth); | ||||
| 892 | |||||
| 893 | 106 | 0s | 106 | 0s |         next_chr();         # spent     0s making 106 calls to JSON::PP::next_chr, avg 0s/call  | 
| 894 | 106 | 0s | 106 | 0s |         white();         # spent     0s making 106 calls to JSON::PP::white, avg 0s/call  | 
| 895 | |||||
| 896 | 106 | 0s | if(defined $ch and $ch eq ']'){ | ||
| 897 | 4 | 0s | --$depth; | ||
| 898 | 4 | 0s | 4 | 0s |             next_chr();             # spent     0s making 4 calls to JSON::PP::next_chr, avg 0s/call  | 
| 899 | 4 | 0s | return $a; | ||
| 900 | } | ||||
| 901 | else { | ||||
| 902 | 102 | 0s | while(defined($ch)){ | ||
| 903 | 139 | 0s | 139 | 0s |                 push @$a, value();                 # spent     0s making 139 calls to JSON::PP::value, avg 0s/call, recursion: max depth 3, sum of overlapping time 0s  | 
| 904 | |||||
| 905 | 139 | 0s | 139 | 0s |                 white();                 # spent     0s making 139 calls to JSON::PP::white, avg 0s/call  | 
| 906 | |||||
| 907 | 139 | 0s | if (!defined $ch) { | ||
| 908 | last; | ||||
| 909 | } | ||||
| 910 | |||||
| 911 | 139 | 0s | if($ch eq ']'){ | ||
| 912 | 102 | 0s | --$depth; | ||
| 913 | 102 | 0s | 102 | 0s |                     next_chr();                     # spent     0s making 102 calls to JSON::PP::next_chr, avg 0s/call  | 
| 914 | 102 | 0s | return $a; | ||
| 915 | } | ||||
| 916 | |||||
| 917 | 37 | 0s | if($ch ne ','){ | ||
| 918 | last; | ||||
| 919 | } | ||||
| 920 | |||||
| 921 | 37 | 0s | 37 | 0s |                 next_chr();                 # spent     0s making 37 calls to JSON::PP::next_chr, avg 0s/call  | 
| 922 | 37 | 0s | 37 | 0s |                 white();                 # spent     0s making 37 calls to JSON::PP::white, avg 0s/call  | 
| 923 | |||||
| 924 | 37 | 0s | if ($relaxed and $ch eq ']') { | ||
| 925 | --$depth; | ||||
| 926 | next_chr(); | ||||
| 927 | return $a; | ||||
| 928 | } | ||||
| 929 | |||||
| 930 | } | ||||
| 931 | } | ||||
| 932 | |||||
| 933 | decode_error(", or ] expected while parsing array"); | ||||
| 934 | } | ||||
| 935 | |||||
| 936 | |||||
| 937 | # spent 109ms (15.6+93.6) within JSON::PP::object which was called 374 times, avg 292µs/call:
# 374 times (15.6ms+93.6ms) by JSON::PP::value at line 725, avg 292µs/call  | ||||
| 938 | 374 | 0s | my $o = $_[0] || {}; # you can use this code to use another hash ref object. | ||
| 939 | 374 | 0s | my $k; | ||
| 940 | |||||
| 941 | 374 | 0s | decode_error('json text or perl structure exceeds maximum nesting level (max_depth set too low?)') | ||
| 942 | if (++$depth > $max_depth); | ||||
| 943 | 374 | 0s | 374 | 0s |         next_chr();         # spent     0s making 374 calls to JSON::PP::next_chr, avg 0s/call  | 
| 944 | 374 | 0s | 374 | 0s |         white();         # spent     0s making 374 calls to JSON::PP::white, avg 0s/call  | 
| 945 | |||||
| 946 | 374 | 0s | if(defined $ch and $ch eq '}'){ | ||
| 947 | 33 | 0s | --$depth; | ||
| 948 | 33 | 0s | 33 | 0s |             next_chr();             # spent     0s making 33 calls to JSON::PP::next_chr, avg 0s/call  | 
| 949 | 33 | 0s | if ($F_HOOK) { | ||
| 950 | return _json_object_hook($o); | ||||
| 951 | } | ||||
| 952 | 33 | 0s | return $o; | ||
| 953 | } | ||||
| 954 | else { | ||||
| 955 | 341 | 0s | while (defined $ch) { | ||
| 956 | 873 | 0s | 873 | 46.8ms |                 $k = ($allow_barekey and $ch ne '"' and $ch ne "'") ? bareKey() : string();                 # spent  46.8ms making 873 calls to JSON::PP::string, avg 54µs/call  | 
| 957 | 873 | 0s | 873 | 0s |                 white();                 # spent     0s making 873 calls to JSON::PP::white, avg 0s/call  | 
| 958 | |||||
| 959 | 873 | 0s | if(!defined $ch or $ch ne ':'){ | ||
| 960 | $at--; | ||||
| 961 | decode_error("':' expected"); | ||||
| 962 | } | ||||
| 963 | |||||
| 964 | 873 | 0s | 873 | 0s |                 next_chr();                 # spent     0s making 873 calls to JSON::PP::next_chr, avg 0s/call  | 
| 965 | 873 | 0s | 873 | 0s |                 $o->{$k} = value();                 # spent  62.4ms making 873 calls to JSON::PP::value, avg 71µs/call, recursion: max depth 4, sum of overlapping time 62.4ms  | 
| 966 | 873 | 0s | 873 | 0s |                 white();                 # spent     0s making 873 calls to JSON::PP::white, avg 0s/call  | 
| 967 | |||||
| 968 | 873 | 0s | last if (!defined $ch); | ||
| 969 | |||||
| 970 | 873 | 0s | if($ch eq '}'){ | ||
| 971 | 341 | 0s | --$depth; | ||
| 972 | 341 | 0s | 341 | 0s |                     next_chr();                     # spent     0s making 341 calls to JSON::PP::next_chr, avg 0s/call  | 
| 973 | 341 | 0s | if ($F_HOOK) { | ||
| 974 | return _json_object_hook($o); | ||||
| 975 | } | ||||
| 976 | 341 | 0s | return $o; | ||
| 977 | } | ||||
| 978 | |||||
| 979 | 532 | 0s | if($ch ne ','){ | ||
| 980 | last; | ||||
| 981 | } | ||||
| 982 | |||||
| 983 | 532 | 0s | 532 | 0s |                 next_chr();                 # spent     0s making 532 calls to JSON::PP::next_chr, avg 0s/call  | 
| 984 | 532 | 0s | 532 | 0s |                 white();                 # spent     0s making 532 calls to JSON::PP::white, avg 0s/call  | 
| 985 | |||||
| 986 | 532 | 0s | if ($relaxed and $ch eq '}') { | ||
| 987 | --$depth; | ||||
| 988 | next_chr(); | ||||
| 989 | if ($F_HOOK) { | ||||
| 990 | return _json_object_hook($o); | ||||
| 991 | } | ||||
| 992 | return $o; | ||||
| 993 | } | ||||
| 994 | |||||
| 995 | } | ||||
| 996 | |||||
| 997 | } | ||||
| 998 | |||||
| 999 | $at--; | ||||
| 1000 | decode_error(", or } expected while parsing object/hash"); | ||||
| 1001 | } | ||||
| 1002 | |||||
| 1003 | |||||
| 1004 | sub bareKey { # doesn't strictly follow Standard ECMA-262 3rd Edition | ||||
| 1005 | my $key; | ||||
| 1006 | while($ch =~ /[^\x00-\x23\x25-\x2F\x3A-\x40\x5B-\x5E\x60\x7B-\x7F]/){ | ||||
| 1007 | $key .= $ch; | ||||
| 1008 | next_chr(); | ||||
| 1009 | } | ||||
| 1010 | return $key; | ||||
| 1011 | } | ||||
| 1012 | |||||
| 1013 | |||||
| 1014 | sub word { | ||||
| 1015 | my $word = substr($text,$at-1,4); | ||||
| 1016 | |||||
| 1017 | if($word eq 'true'){ | ||||
| 1018 | $at += 3; | ||||
| 1019 | next_chr; | ||||
| 1020 | return $JSON::PP::true; | ||||
| 1021 | } | ||||
| 1022 | elsif($word eq 'null'){ | ||||
| 1023 | $at += 3; | ||||
| 1024 | next_chr; | ||||
| 1025 | return undef; | ||||
| 1026 | } | ||||
| 1027 | elsif($word eq 'fals'){ | ||||
| 1028 | $at += 3; | ||||
| 1029 | if(substr($text,$at,1) eq 'e'){ | ||||
| 1030 | $at++; | ||||
| 1031 | next_chr; | ||||
| 1032 | return $JSON::PP::false; | ||||
| 1033 | } | ||||
| 1034 | } | ||||
| 1035 | |||||
| 1036 | $at--; # for decode_error report | ||||
| 1037 | |||||
| 1038 | decode_error("'null' expected") if ($word =~ /^n/); | ||||
| 1039 | decode_error("'true' expected") if ($word =~ /^t/); | ||||
| 1040 | decode_error("'false' expected") if ($word =~ /^f/); | ||||
| 1041 | decode_error("malformed JSON string, neither array, object, number, string or atom"); | ||||
| 1042 | } | ||||
| 1043 | |||||
| 1044 | |||||
| 1045 | # spent 0s within JSON::PP::number which was called 54 times, avg 0s/call:
# 54 times (0s+0s) by JSON::PP::value at line 728, avg 0s/call  | ||||
| 1046 | 54 | 0s | my $n = ''; | ||
| 1047 | 54 | 0s | my $v; | ||
| 1048 | |||||
| 1049 | # According to RFC4627, hex or oct digts are invalid. | ||||
| 1050 | 54 | 0s | if($ch eq '0'){ | ||
| 1051 | 24 | 0s | my $peek = substr($text,$at,1); | ||
| 1052 | 24 | 0s | 24 | 0s |             my $hex  = $peek =~ /[xX]/; # 0 or 1             # spent     0s making 24 calls to JSON::PP::CORE:match, avg 0s/call  | 
| 1053 | |||||
| 1054 | 24 | 0s | if($hex){ | ||
| 1055 | decode_error("malformed number (leading zero must not be followed by another digit)"); | ||||
| 1056 | ($n) = ( substr($text, $at+1) =~ /^([0-9a-fA-F]+)/); | ||||
| 1057 | } | ||||
| 1058 | else{ # oct | ||||
| 1059 | 24 | 0s | 24 | 0s |                 ($n) = ( substr($text, $at) =~ /^([0-7]+)/);                 # spent     0s making 24 calls to JSON::PP::CORE:match, avg 0s/call  | 
| 1060 | 24 | 0s | if (defined $n and length $n > 1) { | ||
| 1061 | decode_error("malformed number (leading zero must not be followed by another digit)"); | ||||
| 1062 | } | ||||
| 1063 | } | ||||
| 1064 | |||||
| 1065 | 24 | 0s | if(defined $n and length($n)){ | ||
| 1066 | if (!$hex and length($n) == 1) { | ||||
| 1067 | decode_error("malformed number (leading zero must not be followed by another digit)"); | ||||
| 1068 | } | ||||
| 1069 | $at += length($n) + $hex; | ||||
| 1070 | next_chr; | ||||
| 1071 | return $hex ? hex($n) : oct($n); | ||||
| 1072 | } | ||||
| 1073 | } | ||||
| 1074 | |||||
| 1075 | 54 | 0s | if($ch eq '-'){ | ||
| 1076 | $n = '-'; | ||||
| 1077 | next_chr; | ||||
| 1078 | if (!defined $ch or $ch !~ /\d/) { | ||||
| 1079 | decode_error("malformed number (no digits after initial minus)"); | ||||
| 1080 | } | ||||
| 1081 | } | ||||
| 1082 | |||||
| 1083 | 54 | 0s | 54 | 0s |         while(defined $ch and $ch =~ /\d/){         # spent     0s making 54 calls to JSON::PP::CORE:match, avg 0s/call  | 
| 1084 | 54 | 0s | $n .= $ch; | ||
| 1085 | 54 | 0s | 108 | 0s |             next_chr;             # spent     0s making 54 calls to JSON::PP::CORE:match, avg 0s/call
            # spent     0s making 54 calls to JSON::PP::next_chr, avg 0s/call  | 
| 1086 | } | ||||
| 1087 | |||||
| 1088 | 54 | 0s | if(defined $ch and $ch eq '.'){ | ||
| 1089 | 4 | 0s | $n .= '.'; | ||
| 1090 | |||||
| 1091 | 4 | 0s | 4 | 0s |             next_chr;             # spent     0s making 4 calls to JSON::PP::next_chr, avg 0s/call  | 
| 1092 | 4 | 0s | 4 | 0s |             if (!defined $ch or $ch !~ /\d/) {             # spent     0s making 4 calls to JSON::PP::CORE:match, avg 0s/call  | 
| 1093 | decode_error("malformed number (no digits after decimal point)"); | ||||
| 1094 | } | ||||
| 1095 | else { | ||||
| 1096 | 4 | 0s | $n .= $ch; | ||
| 1097 | } | ||||
| 1098 | |||||
| 1099 | 4 | 0s | 8 | 0s |             while(defined(next_chr) and $ch =~ /\d/){             # spent     0s making 4 calls to JSON::PP::CORE:match, avg 0s/call
            # spent     0s making 4 calls to JSON::PP::next_chr, avg 0s/call  | 
| 1100 | $n .= $ch; | ||||
| 1101 | } | ||||
| 1102 | } | ||||
| 1103 | |||||
| 1104 | 54 | 0s | if(defined $ch and ($ch eq 'e' or $ch eq 'E')){ | ||
| 1105 | $n .= $ch; | ||||
| 1106 | next_chr; | ||||
| 1107 | |||||
| 1108 | if(defined($ch) and ($ch eq '+' or $ch eq '-')){ | ||||
| 1109 | $n .= $ch; | ||||
| 1110 | next_chr; | ||||
| 1111 | if (!defined $ch or $ch =~ /\D/) { | ||||
| 1112 | decode_error("malformed number (no digits after exp sign)"); | ||||
| 1113 | } | ||||
| 1114 | $n .= $ch; | ||||
| 1115 | } | ||||
| 1116 | elsif(defined($ch) and $ch =~ /\d/){ | ||||
| 1117 | $n .= $ch; | ||||
| 1118 | } | ||||
| 1119 | else { | ||||
| 1120 | decode_error("malformed number (no digits after exp sign)"); | ||||
| 1121 | } | ||||
| 1122 | |||||
| 1123 | while(defined(next_chr) and $ch =~ /\d/){ | ||||
| 1124 | $n .= $ch; | ||||
| 1125 | } | ||||
| 1126 | |||||
| 1127 | } | ||||
| 1128 | |||||
| 1129 | 54 | 0s | $v .= $n; | ||
| 1130 | |||||
| 1131 | 54 | 0s | 54 | 0s |         if ($v !~ /[.eE]/ and length $v > $max_intsize) {         # spent     0s making 54 calls to JSON::PP::CORE:match, avg 0s/call  | 
| 1132 | if ($allow_bigint) { # from Adam Sussman | ||||
| 1133 | require Math::BigInt; | ||||
| 1134 | return Math::BigInt->new($v); | ||||
| 1135 | } | ||||
| 1136 | else { | ||||
| 1137 | return "$v"; | ||||
| 1138 | } | ||||
| 1139 | } | ||||
| 1140 | elsif ($allow_bigint) { | ||||
| 1141 | require Math::BigFloat; | ||||
| 1142 | return Math::BigFloat->new($v); | ||||
| 1143 | } | ||||
| 1144 | |||||
| 1145 | 54 | 0s | return 0+$v; | ||
| 1146 | } | ||||
| 1147 | |||||
| 1148 | |||||
| 1149 | sub is_valid_utf8 { | ||||
| 1150 | |||||
| 1151 | $utf8_len = $_[0] =~ /[\x00-\x7F]/ ? 1 | ||||
| 1152 | : $_[0] =~ /[\xC2-\xDF]/ ? 2 | ||||
| 1153 | : $_[0] =~ /[\xE0-\xEF]/ ? 3 | ||||
| 1154 | : $_[0] =~ /[\xF0-\xF4]/ ? 4 | ||||
| 1155 | : 0 | ||||
| 1156 | ; | ||||
| 1157 | |||||
| 1158 | return unless $utf8_len; | ||||
| 1159 | |||||
| 1160 | my $is_valid_utf8 = substr($text, $at - 1, $utf8_len); | ||||
| 1161 | |||||
| 1162 | return ( $is_valid_utf8 =~ /^(?: | ||||
| 1163 | [\x00-\x7F] | ||||
| 1164 | |[\xC2-\xDF][\x80-\xBF] | ||||
| 1165 | |[\xE0][\xA0-\xBF][\x80-\xBF] | ||||
| 1166 | |[\xE1-\xEC][\x80-\xBF][\x80-\xBF] | ||||
| 1167 | |[\xED][\x80-\x9F][\x80-\xBF] | ||||
| 1168 | |[\xEE-\xEF][\x80-\xBF][\x80-\xBF] | ||||
| 1169 | |[\xF0][\x90-\xBF][\x80-\xBF][\x80-\xBF] | ||||
| 1170 | |[\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF] | ||||
| 1171 | |[\xF4][\x80-\x8F][\x80-\xBF][\x80-\xBF] | ||||
| 1172 | )$/x ) ? $is_valid_utf8 : ''; | ||||
| 1173 | } | ||||
| 1174 | |||||
| 1175 | |||||
| 1176 | sub decode_error { | ||||
| 1177 | my $error = shift; | ||||
| 1178 | my $no_rep = shift; | ||||
| 1179 | my $str = defined $text ? substr($text, $at) : ''; | ||||
| 1180 | my $mess = ''; | ||||
| 1181 | my $type = $] >= 5.008 ? 'U*' | ||||
| 1182 | : $] < 5.006 ? 'C*' | ||||
| 1183 | : utf8::is_utf8( $str ) ? 'U*' # 5.6 | ||||
| 1184 | : 'C*' | ||||
| 1185 | ; | ||||
| 1186 | |||||
| 1187 | for my $c ( unpack( $type, $str ) ) { # emulate pv_uni_display() ? | ||||
| 1188 | $mess .= $c == 0x07 ? '\a' | ||||
| 1189 | : $c == 0x09 ? '\t' | ||||
| 1190 | : $c == 0x0a ? '\n' | ||||
| 1191 | : $c == 0x0d ? '\r' | ||||
| 1192 | : $c == 0x0c ? '\f' | ||||
| 1193 | : $c < 0x20 ? sprintf('\x{%x}', $c) | ||||
| 1194 | : $c == 0x5c ? '\\\\' | ||||
| 1195 | : $c < 0x80 ? chr($c) | ||||
| 1196 | : sprintf('\x{%x}', $c) | ||||
| 1197 | ; | ||||
| 1198 | if ( length $mess >= 20 ) { | ||||
| 1199 | $mess .= '...'; | ||||
| 1200 | last; | ||||
| 1201 | } | ||||
| 1202 | } | ||||
| 1203 | |||||
| 1204 | unless ( length $mess ) { | ||||
| 1205 | $mess = '(end of string)'; | ||||
| 1206 | } | ||||
| 1207 | |||||
| 1208 | Carp::croak ( | ||||
| 1209 | $no_rep ? "$error" : "$error, at character offset $at (before \"$mess\")" | ||||
| 1210 | ); | ||||
| 1211 | |||||
| 1212 | } | ||||
| 1213 | |||||
| 1214 | |||||
| 1215 | sub _json_object_hook { | ||||
| 1216 | my $o = $_[0]; | ||||
| 1217 | my @ks = keys %{$o}; | ||||
| 1218 | |||||
| 1219 | if ( $cb_sk_object and @ks == 1 and exists $cb_sk_object->{ $ks[0] } and ref $cb_sk_object->{ $ks[0] } ) { | ||||
| 1220 | my @val = $cb_sk_object->{ $ks[0] }->( $o->{$ks[0]} ); | ||||
| 1221 | if (@val == 1) { | ||||
| 1222 | return $val[0]; | ||||
| 1223 | } | ||||
| 1224 | } | ||||
| 1225 | |||||
| 1226 | my @val = $cb_object->($o) if ($cb_object); | ||||
| 1227 | if (@val == 0 or @val > 1) { | ||||
| 1228 | return $o; | ||||
| 1229 | } | ||||
| 1230 | else { | ||||
| 1231 | return $val[0]; | ||||
| 1232 | } | ||||
| 1233 | } | ||||
| 1234 | |||||
| 1235 | |||||
| 1236 | sub PP_decode_box { | ||||
| 1237 | { | ||||
| 1238 | text => $text, | ||||
| 1239 | at => $at, | ||||
| 1240 | ch => $ch, | ||||
| 1241 | len => $len, | ||||
| 1242 | depth => $depth, | ||||
| 1243 | encoding => $encoding, | ||||
| 1244 | is_valid_utf8 => $is_valid_utf8, | ||||
| 1245 | }; | ||||
| 1246 | } | ||||
| 1247 | |||||
| 1248 | } # PARSE | ||||
| 1249 | |||||
| 1250 | |||||
| 1251 | sub _decode_surrogates { # from perlunicode | ||||
| 1252 | my $uni = 0x10000 + (hex($_[0]) - 0xD800) * 0x400 + (hex($_[1]) - 0xDC00); | ||||
| 1253 | my $un = pack('U*', $uni); | ||||
| 1254 | utf8::encode( $un ); | ||||
| 1255 | return $un; | ||||
| 1256 | } | ||||
| 1257 | |||||
| 1258 | |||||
| 1259 | sub _decode_unicode { | ||||
| 1260 | my $un = pack('U', hex shift); | ||||
| 1261 | utf8::encode( $un ); | ||||
| 1262 | return $un; | ||||
| 1263 | } | ||||
| 1264 | |||||
| 1265 | # | ||||
| 1266 | # Setup for various Perl versions (the code from JSON::PP58) | ||||
| 1267 | # | ||||
| 1268 | |||||
| 1269 | # spent 0s within JSON::PP::BEGIN@1269 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1325  | ||||
| 1270 | |||||
| 1271 | 1 | 0s | unless ( defined &utf8::is_utf8 ) { | ||
| 1272 | require Encode; | ||||
| 1273 | *utf8::is_utf8 = *Encode::is_utf8; | ||||
| 1274 | } | ||||
| 1275 | |||||
| 1276 | 1 | 0s | if ( $] >= 5.008 ) { | ||
| 1277 | 1 | 0s | *JSON::PP::JSON_PP_encode_ascii = \&_encode_ascii; | ||
| 1278 | 1 | 0s | *JSON::PP::JSON_PP_encode_latin1 = \&_encode_latin1; | ||
| 1279 | 1 | 0s | *JSON::PP::JSON_PP_decode_surrogates = \&_decode_surrogates; | ||
| 1280 | 1 | 0s | *JSON::PP::JSON_PP_decode_unicode = \&_decode_unicode; | ||
| 1281 | } | ||||
| 1282 | |||||
| 1283 | 1 | 0s | if ($] >= 5.008 and $] < 5.008003) { # join() in 5.8.0 - 5.8.2 is broken. | ||
| 1284 | package JSON::PP; | ||||
| 1285 | require subs; | ||||
| 1286 | subs->import('join'); | ||||
| 1287 | eval q| | ||||
| 1288 | sub join { | ||||
| 1289 | return '' if (@_ < 2); | ||||
| 1290 | my $j = shift; | ||||
| 1291 | my $str = shift; | ||||
| 1292 | for (@_) { $str .= $j . $_; } | ||||
| 1293 | return $str; | ||||
| 1294 | } | ||||
| 1295 | |; | ||||
| 1296 | } | ||||
| 1297 | |||||
| 1298 | |||||
| 1299 | sub JSON::PP::incr_parse { | ||||
| 1300 | local $Carp::CarpLevel = 1; | ||||
| 1301 | ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_parse( @_ ); | ||||
| 1302 | } | ||||
| 1303 | |||||
| 1304 | |||||
| 1305 | sub JSON::PP::incr_skip { | ||||
| 1306 | ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_skip; | ||||
| 1307 | } | ||||
| 1308 | |||||
| 1309 | |||||
| 1310 | sub JSON::PP::incr_reset { | ||||
| 1311 | ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_reset; | ||||
| 1312 | } | ||||
| 1313 | |||||
| 1314 | 1 | 0s | eval q{ | ||
| 1315 | sub JSON::PP::incr_text : lvalue { | ||||
| 1316 | $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new; | ||||
| 1317 | |||||
| 1318 | if ( $_[0]->{_incr_parser}->{incr_parsing} ) { | ||||
| 1319 | Carp::croak("incr_text can not be called when the incremental parser already started parsing"); | ||||
| 1320 | } | ||||
| 1321 | $_[0]->{_incr_parser}->{incr_text}; | ||||
| 1322 | } | ||||
| 1323 | } if ( $] >= 5.006 ); | ||||
| 1324 | |||||
| 1325 | 1 | 0s | 1 | 0s | } # Setup for various Perl versions (the code from JSON::PP58) # spent     0s making 1 call to JSON::PP::BEGIN@1269  | 
| 1326 | |||||
| 1327 | |||||
| 1328 | ############################### | ||||
| 1329 | # Utilities | ||||
| 1330 | # | ||||
| 1331 | |||||
| 1332 | # spent 0s within JSON::PP::BEGIN@1332 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1385  | ||||
| 1333 | 1 | 0s |     eval 'require Scalar::Util';     # spent     0s executing statements in string eval  | ||
| 1334 | 1 | 0s | unless($@){ | ||
| 1335 | 1 | 0s | *JSON::PP::blessed = \&Scalar::Util::blessed; | ||
| 1336 | 1 | 0s | *JSON::PP::reftype = \&Scalar::Util::reftype; | ||
| 1337 | 1 | 0s | *JSON::PP::refaddr = \&Scalar::Util::refaddr; | ||
| 1338 | } | ||||
| 1339 | else{ # This code is from Sclar::Util. | ||||
| 1340 | # warn $@; | ||||
| 1341 | eval 'sub UNIVERSAL::a_sub_not_likely_to_be_here { ref($_[0]) }'; | ||||
| 1342 | *JSON::PP::blessed = sub { | ||||
| 1343 | local($@, $SIG{__DIE__}, $SIG{__WARN__}); | ||||
| 1344 | ref($_[0]) ? eval { $_[0]->a_sub_not_likely_to_be_here } : undef; | ||||
| 1345 | }; | ||||
| 1346 | my %tmap = qw( | ||||
| 1347 | B::NULL SCALAR | ||||
| 1348 | B::HV HASH | ||||
| 1349 | B::AV ARRAY | ||||
| 1350 | B::CV CODE | ||||
| 1351 | B::IO IO | ||||
| 1352 | B::GV GLOB | ||||
| 1353 | B::REGEXP REGEXP | ||||
| 1354 | ); | ||||
| 1355 | *JSON::PP::reftype = sub { | ||||
| 1356 | my $r = shift; | ||||
| 1357 | |||||
| 1358 | return undef unless length(ref($r)); | ||||
| 1359 | |||||
| 1360 | my $t = ref(B::svref_2object($r)); | ||||
| 1361 | |||||
| 1362 | return | ||||
| 1363 | exists $tmap{$t} ? $tmap{$t} | ||||
| 1364 | : length(ref($$r)) ? 'REF' | ||||
| 1365 | : 'SCALAR'; | ||||
| 1366 | }; | ||||
| 1367 | *JSON::PP::refaddr = sub { | ||||
| 1368 | return undef unless length(ref($_[0])); | ||||
| 1369 | |||||
| 1370 | my $addr; | ||||
| 1371 | if(defined(my $pkg = blessed($_[0]))) { | ||||
| 1372 | $addr .= bless $_[0], 'Scalar::Util::Fake'; | ||||
| 1373 | bless $_[0], $pkg; | ||||
| 1374 | } | ||||
| 1375 | else { | ||||
| 1376 | $addr .= $_[0] | ||||
| 1377 | } | ||||
| 1378 | |||||
| 1379 | $addr =~ /0x(\w+)/; | ||||
| 1380 | local $^W; | ||||
| 1381 | #no warnings 'portable'; | ||||
| 1382 | hex($1); | ||||
| 1383 | } | ||||
| 1384 | } | ||||
| 1385 | 1 | 0s | 1 | 0s | } # spent     0s making 1 call to JSON::PP::BEGIN@1332  | 
| 1386 | |||||
| 1387 | |||||
| 1388 | # shamely copied and modified from JSON::XS code. | ||||
| 1389 | |||||
| 1390 | 1 | 0s | $JSON::PP::true = do { bless \(my $dummy = 1), "JSON::PP::Boolean" }; | ||
| 1391 | 1 | 0s | $JSON::PP::false = do { bless \(my $dummy = 0), "JSON::PP::Boolean" }; | ||
| 1392 | |||||
| 1393 | sub is_bool { defined $_[0] and UNIVERSAL::isa($_[0], "JSON::PP::Boolean"); } | ||||
| 1394 | |||||
| 1395 | sub true { $JSON::PP::true } | ||||
| 1396 | sub false { $JSON::PP::false } | ||||
| 1397 | sub null { undef; } | ||||
| 1398 | |||||
| 1399 | ############################### | ||||
| 1400 | |||||
| 1401 | package JSON::PP::Boolean; | ||||
| 1402 | |||||
| 1403 | # spent 0s within JSON::PP::Boolean::BEGIN@1403 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1408  | ||||
| 1404 | "0+" => sub { ${$_[0]} }, | ||||
| 1405 | "++" => sub { $_[0] = ${$_[0]} + 1 }, | ||||
| 1406 | "--" => sub { $_[0] = ${$_[0]} - 1 }, | ||||
| 1407 | 1 | 0s | 1 | 0s |    fallback => 1,    # spent     0s making 1 call to overload::import  | 
| 1408 | 1 | 0s | 1 | 0s | ); # spent     0s making 1 call to JSON::PP::Boolean::BEGIN@1403  | 
| 1409 | |||||
| 1410 | |||||
| 1411 | ############################### | ||||
| 1412 | |||||
| 1413 | package JSON::PP::IncrParser; | ||||
| 1414 | |||||
| 1415 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::IncrParser::BEGIN@1415 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1415 # spent     0s making 1 call to JSON::PP::IncrParser::BEGIN@1415
# spent     0s making 1 call to strict::import  | 
| 1416 | |||||
| 1417 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::IncrParser::BEGIN@1417 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1417 # spent     0s making 1 call to JSON::PP::IncrParser::BEGIN@1417
# spent     0s making 1 call to constant::import  | 
| 1418 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::IncrParser::BEGIN@1418 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1418 # spent     0s making 1 call to JSON::PP::IncrParser::BEGIN@1418
# spent     0s making 1 call to constant::import  | 
| 1419 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::IncrParser::BEGIN@1419 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1419 # spent     0s making 1 call to JSON::PP::IncrParser::BEGIN@1419
# spent     0s making 1 call to constant::import  | 
| 1420 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::IncrParser::BEGIN@1420 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1420 # spent     0s making 1 call to JSON::PP::IncrParser::BEGIN@1420
# spent     0s making 1 call to constant::import  | 
| 1421 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::IncrParser::BEGIN@1421 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1421 # spent     0s making 1 call to JSON::PP::IncrParser::BEGIN@1421
# spent     0s making 1 call to constant::import  | 
| 1422 | 2 | 0s | 2 | 0s | # spent 0s within JSON::PP::IncrParser::BEGIN@1422 which was called:
#    once (0s+0s) by Parse::CPAN::Meta::_can_load at line 1422 # spent     0s making 1 call to JSON::PP::IncrParser::BEGIN@1422
# spent     0s making 1 call to constant::import  | 
| 1423 | |||||
| 1424 | 1 | 0s | $JSON::PP::IncrParser::VERSION = '1.01'; | ||
| 1425 | |||||
| 1426 | 1 | 0s | my $unpack_format = $] < 5.006 ? 'C*' : 'U*'; | ||
| 1427 | |||||
| 1428 | sub new { | ||||
| 1429 | my ( $class ) = @_; | ||||
| 1430 | |||||
| 1431 | bless { | ||||
| 1432 | incr_nest => 0, | ||||
| 1433 | incr_text => undef, | ||||
| 1434 | incr_parsing => 0, | ||||
| 1435 | incr_p => 0, | ||||
| 1436 | }, $class; | ||||
| 1437 | } | ||||
| 1438 | |||||
| 1439 | |||||
| 1440 | sub incr_parse { | ||||
| 1441 | my ( $self, $coder, $text ) = @_; | ||||
| 1442 | |||||
| 1443 | $self->{incr_text} = '' unless ( defined $self->{incr_text} ); | ||||
| 1444 | |||||
| 1445 | if ( defined $text ) { | ||||
| 1446 | if ( utf8::is_utf8( $text ) and !utf8::is_utf8( $self->{incr_text} ) ) { | ||||
| 1447 | utf8::upgrade( $self->{incr_text} ) ; | ||||
| 1448 | utf8::decode( $self->{incr_text} ) ; | ||||
| 1449 | } | ||||
| 1450 | $self->{incr_text} .= $text; | ||||
| 1451 | } | ||||
| 1452 | |||||
| 1453 | |||||
| 1454 | my $max_size = $coder->get_max_size; | ||||
| 1455 | |||||
| 1456 | if ( defined wantarray ) { | ||||
| 1457 | |||||
| 1458 | $self->{incr_mode} = INCR_M_WS unless defined $self->{incr_mode}; | ||||
| 1459 | |||||
| 1460 | if ( wantarray ) { | ||||
| 1461 | my @ret; | ||||
| 1462 | |||||
| 1463 | $self->{incr_parsing} = 1; | ||||
| 1464 | |||||
| 1465 | do { | ||||
| 1466 | push @ret, $self->_incr_parse( $coder, $self->{incr_text} ); | ||||
| 1467 | |||||
| 1468 | unless ( !$self->{incr_nest} and $self->{incr_mode} == INCR_M_JSON ) { | ||||
| 1469 | $self->{incr_mode} = INCR_M_WS if $self->{incr_mode} != INCR_M_STR; | ||||
| 1470 | } | ||||
| 1471 | |||||
| 1472 | } until ( length $self->{incr_text} >= $self->{incr_p} ); | ||||
| 1473 | |||||
| 1474 | $self->{incr_parsing} = 0; | ||||
| 1475 | |||||
| 1476 | return @ret; | ||||
| 1477 | } | ||||
| 1478 | else { # in scalar context | ||||
| 1479 | $self->{incr_parsing} = 1; | ||||
| 1480 | my $obj = $self->_incr_parse( $coder, $self->{incr_text} ); | ||||
| 1481 | $self->{incr_parsing} = 0 if defined $obj; # pointed by Martin J. Evans | ||||
| 1482 | return $obj ? $obj : undef; # $obj is an empty string, parsing was completed. | ||||
| 1483 | } | ||||
| 1484 | |||||
| 1485 | } | ||||
| 1486 | |||||
| 1487 | } | ||||
| 1488 | |||||
| 1489 | |||||
| 1490 | sub _incr_parse { | ||||
| 1491 | my ( $self, $coder, $text, $skip ) = @_; | ||||
| 1492 | my $p = $self->{incr_p}; | ||||
| 1493 | my $restore = $p; | ||||
| 1494 | |||||
| 1495 | my @obj; | ||||
| 1496 | my $len = length $text; | ||||
| 1497 | |||||
| 1498 | if ( $self->{incr_mode} == INCR_M_WS ) { | ||||
| 1499 | while ( $len > $p ) { | ||||
| 1500 | my $s = substr( $text, $p, 1 ); | ||||
| 1501 | $p++ and next if ( 0x20 >= unpack($unpack_format, $s) ); | ||||
| 1502 | $self->{incr_mode} = INCR_M_JSON; | ||||
| 1503 | last; | ||||
| 1504 | } | ||||
| 1505 | } | ||||
| 1506 | |||||
| 1507 | while ( $len > $p ) { | ||||
| 1508 | my $s = substr( $text, $p++, 1 ); | ||||
| 1509 | |||||
| 1510 | if ( $s eq '"' ) { | ||||
| 1511 | if (substr( $text, $p - 2, 1 ) eq '\\' ) { | ||||
| 1512 | next; | ||||
| 1513 | } | ||||
| 1514 | |||||
| 1515 | if ( $self->{incr_mode} != INCR_M_STR ) { | ||||
| 1516 | $self->{incr_mode} = INCR_M_STR; | ||||
| 1517 | } | ||||
| 1518 | else { | ||||
| 1519 | $self->{incr_mode} = INCR_M_JSON; | ||||
| 1520 | unless ( $self->{incr_nest} ) { | ||||
| 1521 | last; | ||||
| 1522 | } | ||||
| 1523 | } | ||||
| 1524 | } | ||||
| 1525 | |||||
| 1526 | if ( $self->{incr_mode} == INCR_M_JSON ) { | ||||
| 1527 | |||||
| 1528 | if ( $s eq '[' or $s eq '{' ) { | ||||
| 1529 | if ( ++$self->{incr_nest} > $coder->get_max_depth ) { | ||||
| 1530 | Carp::croak('json text or perl structure exceeds maximum nesting level (max_depth set too low?)'); | ||||
| 1531 | } | ||||
| 1532 | } | ||||
| 1533 | elsif ( $s eq ']' or $s eq '}' ) { | ||||
| 1534 | last if ( --$self->{incr_nest} <= 0 ); | ||||
| 1535 | } | ||||
| 1536 | elsif ( $s eq '#' ) { | ||||
| 1537 | while ( $len > $p ) { | ||||
| 1538 | last if substr( $text, $p++, 1 ) eq "\n"; | ||||
| 1539 | } | ||||
| 1540 | } | ||||
| 1541 | |||||
| 1542 | } | ||||
| 1543 | |||||
| 1544 | } | ||||
| 1545 | |||||
| 1546 | $self->{incr_p} = $p; | ||||
| 1547 | |||||
| 1548 | return if ( $self->{incr_mode} == INCR_M_STR and not $self->{incr_nest} ); | ||||
| 1549 | return if ( $self->{incr_mode} == INCR_M_JSON and $self->{incr_nest} > 0 ); | ||||
| 1550 | |||||
| 1551 | return '' unless ( length substr( $self->{incr_text}, 0, $p ) ); | ||||
| 1552 | |||||
| 1553 | local $Carp::CarpLevel = 2; | ||||
| 1554 | |||||
| 1555 | $self->{incr_p} = $restore; | ||||
| 1556 | $self->{incr_c} = $p; | ||||
| 1557 | |||||
| 1558 | my ( $obj, $tail ) = $coder->PP_decode_json( substr( $self->{incr_text}, 0, $p ), 0x10000001 ); | ||||
| 1559 | |||||
| 1560 | $self->{incr_text} = substr( $self->{incr_text}, $p ); | ||||
| 1561 | $self->{incr_p} = 0; | ||||
| 1562 | |||||
| 1563 | return $obj || ''; | ||||
| 1564 | } | ||||
| 1565 | |||||
| 1566 | |||||
| 1567 | sub incr_text { | ||||
| 1568 | if ( $_[0]->{incr_parsing} ) { | ||||
| 1569 | Carp::croak("incr_text can not be called when the incremental parser already started parsing"); | ||||
| 1570 | } | ||||
| 1571 | $_[0]->{incr_text}; | ||||
| 1572 | } | ||||
| 1573 | |||||
| 1574 | |||||
| 1575 | sub incr_skip { | ||||
| 1576 | my $self = shift; | ||||
| 1577 | $self->{incr_text} = substr( $self->{incr_text}, $self->{incr_c} ); | ||||
| 1578 | $self->{incr_p} = 0; | ||||
| 1579 | } | ||||
| 1580 | |||||
| 1581 | |||||
| 1582 | sub incr_reset { | ||||
| 1583 | my $self = shift; | ||||
| 1584 | $self->{incr_text} = undef; | ||||
| 1585 | $self->{incr_p} = 0; | ||||
| 1586 | $self->{incr_mode} = 0; | ||||
| 1587 | $self->{incr_nest} = 0; | ||||
| 1588 | $self->{incr_parsing} = 0; | ||||
| 1589 | } | ||||
| 1590 | |||||
| 1591 | ############################### | ||||
| 1592 | |||||
| 1593 | |||||
| 1594 | 1 | 0s | 1; | ||
| 1595 | __END__ | ||||
# spent 0s within JSON::PP::CORE:match which was called 17361 times, avg 0s/call:
# 17072 times (0s+0s) by JSON::PP::string at line 822, avg 0s/call
#    54 times (0s+0s) by JSON::PP::number at line 1085, avg 0s/call
#    54 times (0s+0s) by JSON::PP::number at line 1083, avg 0s/call
#    54 times (0s+0s) by JSON::PP::number at line 1131, avg 0s/call
#    54 times (0s+0s) by JSON::PP::value at line 728, avg 0s/call
#    24 times (0s+0s) by JSON::PP::number at line 1052, avg 0s/call
#    24 times (0s+0s) by JSON::PP::number at line 1059, avg 0s/call
#    17 times (0s+0s) by JSON::PP::BEGIN@584 at line 589, avg 0s/call
#     4 times (0s+0s) by JSON::PP::number at line 1092, avg 0s/call
#     4 times (0s+0s) by JSON::PP::number at line 1099, avg 0s/call  | |||||
# spent 0s within JSON::PP::CORE:sort which was called 96 times, avg 0s/call:
# 96 times (0s+0s) by JSON::PP::_sort at line 509, avg 0s/call  | |||||
sub JSON::PP::CORE:subst; # opcode  | |||||
# spent 0s within JSON::PP::CORE:unpack which was called 55 times, avg 0s/call:
# 55 times (0s+0s) by JSON::PP::PP_decode_json at line 677, avg 0s/call  |