| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/JSON/Pointer.pm |
| Statements | Executed 380420 statements in 820ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 47846 | 1 | 1 | 546ms | 871ms | Mojo::JSON::Pointer::_pointer |
| 47846 | 3 | 2 | 177ms | 1.05s | Mojo::JSON::Pointer::get |
| 146708 | 3 | 1 | 84.0ms | 84.0ms | Mojo::JSON::Pointer::CORE:subst (opcode) |
| 211 | 1 | 1 | 1.33ms | 1.33ms | Mojo::JSON::Pointer::CORE:match (opcode) |
| 15 | 2 | 2 | 70µs | 115µs | Mojo::JSON::Pointer::new |
| 1 | 1 | 1 | 34µs | 229µs | Mojo::JSON::Pointer::BEGIN@2 |
| 0 | 0 | 0 | 0s | 0s | Mojo::JSON::Pointer::contains |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Mojo::JSON::Pointer; | ||||
| 2 | 2 | 377µs | 2 | 424µs | # spent 229µs (34+195) within Mojo::JSON::Pointer::BEGIN@2 which was called:
# once (34µs+195µs) by Moo::_Utils::_require at line 2 # spent 229µs making 1 call to Mojo::JSON::Pointer::BEGIN@2
# spent 195µs making 1 call to Mojo::Base::import |
| 3 | |||||
| 4 | 1 | 2µs | 1 | 40µs | has 'data'; # spent 40µs making 1 call to Mojo::JSON::Pointer::has |
| 5 | |||||
| 6 | sub contains { shift->_pointer(0, @_) } | ||||
| 7 | 47846 | 172ms | 47846 | 871ms | # spent 1.05s (177ms+871ms) within Mojo::JSON::Pointer::get which was called 47846 times, avg 22µs/call:
# 39123 times (148ms+655ms) by JSON::Schema::Modern::_fetch_from_uri at line 854 of JSON/Schema/Modern.pm, avg 21µs/call
# 7758 times (22.3ms+146ms) by JSON::Schema::Modern::_fetch_from_uri at line 878 of JSON/Schema/Modern.pm, avg 22µs/call
# 965 times (6.04ms+69.3ms) by JSON::Schema::Modern::Document::OpenAPI::traverse at line 161 of JSON/Schema/Modern/Document/OpenAPI.pm, avg 78µs/call # spent 871ms making 47846 calls to Mojo::JSON::Pointer::_pointer, avg 18µs/call |
| 8 | |||||
| 9 | 15 | 66µs | 15 | 45µs | # spent 115µs (70+45) within Mojo::JSON::Pointer::new which was called 15 times, avg 8µs/call:
# 14 times (60µs+39µs) by JSON::Schema::Modern::Document::new at line 53 of (eval 424)[Sub/Quote.pm:3], avg 7µs/call
# once (10µs+6µs) by JSON::Schema::Modern::Document::OpenAPI::new at line 56 of (eval 417)[Sub/Quote.pm:3] # spent 45µs making 15 calls to Mojo::Base::new, avg 3µs/call |
| 10 | |||||
| 11 | # spent 871ms (546+324) within Mojo::JSON::Pointer::_pointer which was called 47846 times, avg 18µs/call:
# 47846 times (546ms+324ms) by Mojo::JSON::Pointer::get at line 7, avg 18µs/call | ||||
| 12 | 47846 | 29.3ms | my ($self, $get, $pointer) = @_; | ||
| 13 | |||||
| 14 | 47846 | 77.1ms | 47846 | 239ms | my $data = $self->data; # spent 239ms making 47846 calls to JSON::Schema::Modern::Document::data, avg 5µs/call |
| 15 | 47846 | 214ms | 47846 | 54.3ms | return length $pointer ? undef : $get ? $data : 1 unless $pointer =~ s!^/!!; # spent 54.3ms making 47846 calls to Mojo::JSON::Pointer::CORE:subst, avg 1µs/call |
| 16 | 20362 | 57.0ms | for my $p (length $pointer ? (split /\//, $pointer, -1) : ($pointer)) { | ||
| 17 | 49431 | 77.5ms | 49431 | 20.3ms | $p =~ s!~1!/!g; # spent 20.3ms making 49431 calls to Mojo::JSON::Pointer::CORE:subst, avg 411ns/call |
| 18 | 49431 | 54.2ms | 49431 | 9.35ms | $p =~ s/~0/~/g; # spent 9.35ms making 49431 calls to Mojo::JSON::Pointer::CORE:subst, avg 189ns/call |
| 19 | |||||
| 20 | # Hash | ||||
| 21 | 49431 | 96.7ms | 211 | 1.33ms | if (ref $data eq 'HASH' && exists $data->{$p}) { $data = $data->{$p} } # spent 1.33ms making 211 calls to Mojo::JSON::Pointer::CORE:match, avg 6µs/call |
| 22 | |||||
| 23 | # Array | ||||
| 24 | elsif (ref $data eq 'ARRAY' && $p =~ /^\d+$/ && @$data > $p) { $data = $data->[$p] } | ||||
| 25 | |||||
| 26 | # Nothing | ||||
| 27 | else { return undef } | ||||
| 28 | } | ||||
| 29 | |||||
| 30 | 20362 | 41.3ms | return $get ? $data : 1; | ||
| 31 | } | ||||
| 32 | |||||
| 33 | 1 | 4µs | 1; | ||
| 34 | |||||
| 35 | =encoding utf8 | ||||
| 36 | |||||
| 37 | =head1 NAME | ||||
| 38 | |||||
| 39 | Mojo::JSON::Pointer - JSON Pointers | ||||
| 40 | |||||
| 41 | =head1 SYNOPSIS | ||||
| 42 | |||||
| 43 | use Mojo::JSON::Pointer; | ||||
| 44 | |||||
| 45 | my $pointer = Mojo::JSON::Pointer->new({foo => [23, 'bar']}); | ||||
| 46 | say $pointer->get('/foo/1'); | ||||
| 47 | say 'Contains "/foo".' if $pointer->contains('/foo'); | ||||
| 48 | |||||
| 49 | =head1 DESCRIPTION | ||||
| 50 | |||||
| 51 | L<Mojo::JSON::Pointer> is an implementation of L<RFC 6901|https://tools.ietf.org/html/rfc6901>. | ||||
| 52 | |||||
| 53 | =head1 ATTRIBUTES | ||||
| 54 | |||||
| 55 | L<Mojo::JSON::Pointer> implements the following attributes. | ||||
| 56 | |||||
| 57 | =head2 data | ||||
| 58 | |||||
| 59 | my $data = $pointer->data; | ||||
| 60 | $pointer = $pointer->data({foo => 'bar'}); | ||||
| 61 | |||||
| 62 | Data structure to be processed. | ||||
| 63 | |||||
| 64 | =head1 METHODS | ||||
| 65 | |||||
| 66 | L<Mojo::JSON::Pointer> inherits all methods from L<Mojo::Base> and implements the following new ones. | ||||
| 67 | |||||
| 68 | =head2 contains | ||||
| 69 | |||||
| 70 | my $bool = $pointer->contains('/foo/1'); | ||||
| 71 | |||||
| 72 | Check if L</"data"> contains a value that can be identified with the given JSON Pointer. | ||||
| 73 | |||||
| 74 | # True | ||||
| 75 | Mojo::JSON::Pointer->new('just a string')->contains(''); | ||||
| 76 | Mojo::JSON::Pointer->new({'♥' => 'mojolicious'})->contains('/♥'); | ||||
| 77 | Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/foo'); | ||||
| 78 | Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/baz/1'); | ||||
| 79 | |||||
| 80 | # False | ||||
| 81 | Mojo::JSON::Pointer->new({'♥' => 'mojolicious'})->contains('/☃'); | ||||
| 82 | Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/bar'); | ||||
| 83 | Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/baz/9'); | ||||
| 84 | |||||
| 85 | =head2 get | ||||
| 86 | |||||
| 87 | my $value = $pointer->get('/foo/bar'); | ||||
| 88 | |||||
| 89 | Extract value from L</"data"> identified by the given JSON Pointer. | ||||
| 90 | |||||
| 91 | # "just a string" | ||||
| 92 | Mojo::JSON::Pointer->new('just a string')->get(''); | ||||
| 93 | |||||
| 94 | # "mojolicious" | ||||
| 95 | Mojo::JSON::Pointer->new({'♥' => 'mojolicious'})->get('/♥'); | ||||
| 96 | |||||
| 97 | # "bar" | ||||
| 98 | Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/foo'); | ||||
| 99 | |||||
| 100 | # "4" | ||||
| 101 | Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/baz/0'); | ||||
| 102 | |||||
| 103 | # "6" | ||||
| 104 | Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/baz/2'); | ||||
| 105 | |||||
| 106 | =head2 new | ||||
| 107 | |||||
| 108 | my $pointer = Mojo::JSON::Pointer->new; | ||||
| 109 | my $pointer = Mojo::JSON::Pointer->new({foo => 'bar'}); | ||||
| 110 | |||||
| 111 | Build new L<Mojo::JSON::Pointer> object. | ||||
| 112 | |||||
| 113 | =head1 SEE ALSO | ||||
| 114 | |||||
| 115 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||
| 116 | |||||
| 117 | =cut | ||||
# spent 1.33ms within Mojo::JSON::Pointer::CORE:match which was called 211 times, avg 6µs/call:
# 211 times (1.33ms+0s) by Mojo::JSON::Pointer::_pointer at line 21, avg 6µs/call | |||||
# spent 84.0ms within Mojo::JSON::Pointer::CORE:subst which was called 146708 times, avg 572ns/call:
# 49431 times (20.3ms+0s) by Mojo::JSON::Pointer::_pointer at line 17, avg 411ns/call
# 49431 times (9.35ms+0s) by Mojo::JSON::Pointer::_pointer at line 18, avg 189ns/call
# 47846 times (54.3ms+0s) by Mojo::JSON::Pointer::_pointer at line 15, avg 1µs/call |