← Index
NYTProf Performance Profile   « line view »
For flows_to_es.pl
  Run on Mon May 9 23:27:59 2016
Reported on Mon May 9 23:28:09 2016

Filename/opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/Serializer/JSON.pm
StatementsExecuted 17 statements in 972µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1113.27ms7.01msSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@8Search::Elasticsearch::Role::Serializer::JSON::BEGIN@8
11117µs357µsSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@3Search::Elasticsearch::Role::Serializer::JSON::BEGIN@3
11113µs54µsSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@7Search::Elasticsearch::Role::Serializer::JSON::BEGIN@7
11112µs264µsSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@6Search::Elasticsearch::Role::Serializer::JSON::BEGIN@6
1119µs291µsSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@9Search::Elasticsearch::Role::Serializer::JSON::BEGIN@9
1117µs44µsSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:3]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:3]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:24]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:24]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:25]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:25]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:46]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:46]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:47]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:47]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:59]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:59]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:62]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:62]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:65]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:65]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:82]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:82]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:85]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:85]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::_set_canonicalSearch::Elasticsearch::Role::Serializer::JSON::_set_canonical
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::decodeSearch::Elasticsearch::Role::Serializer::JSON::decode
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::encodeSearch::Elasticsearch::Role::Serializer::JSON::encode
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::encode_bulkSearch::Elasticsearch::Role::Serializer::JSON::encode_bulk
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::encode_prettySearch::Elasticsearch::Role::Serializer::JSON::encode_pretty
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Search::Elasticsearch::Role::Serializer::JSON;
21600ns$Search::Elasticsearch::Role::Serializer::JSON::VERSION = '2.02';
3460µs3734µs
# spent 44µs (7+37) within Search::Elasticsearch::Role::Serializer::JSON::__ANON__[/opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/Serializer/JSON.pm:3] which was called: # once (7µs+37µs) by import::into at line 34 of Import/Into.pm # spent 357µs (17+340) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@3 which was called: # once (17µs+340µs) by Module::Runtime::require_module at line 3
use Moo::Role;
# spent 357µs making 1 call to Search::Elasticsearch::Role::Serializer::JSON::BEGIN@3 # spent 340µs making 1 call to Moo::Role::import # spent 37µs making 1 call to strictures::import
412µs111µsrequires 'JSON';
# spent 11µs making 1 call to Moo::Role::requires
5
6242µs2516µs
# spent 264µs (12+252) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@6 which was called: # once (12µs+252µs) by Module::Runtime::require_module at line 6
use Search::Elasticsearch::Util qw(throw);
7239µs296µs
# spent 54µs (13+42) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@7 which was called: # once (13µs+42µs) by Module::Runtime::require_module at line 7
use Try::Tiny;
# spent 54µs making 1 call to Search::Elasticsearch::Role::Serializer::JSON::BEGIN@7 # spent 42µs making 1 call to Exporter::import
82132µs27.12ms
# spent 7.01ms (3.27+3.74) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@8 which was called: # once (3.27ms+3.74ms) by Module::Runtime::require_module at line 8
use Encode qw(encode_utf8 decode_utf8 is_utf8);
# spent 7.01ms making 1 call to Search::Elasticsearch::Role::Serializer::JSON::BEGIN@8 # spent 108µs making 1 call to Exporter::import
92673µs2572µs
# spent 291µs (9+281) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@9 which was called: # once (9µs+281µs) by Module::Runtime::require_module at line 9
use namespace::clean;
# spent 291µs making 1 call to Search::Elasticsearch::Role::Serializer::JSON::BEGIN@9 # spent 281µs making 1 call to namespace::clean::import
10
1111µs1148µshas 'mime_type' => ( is => 'ro', default => 'application/json' );
# spent 148µs making 1 call to Moo::Role::has
12
1311µs1897µswith 'Search::Elasticsearch::Role::Serializer';
# spent 897µs making 1 call to Moo::Role::with
14
15#===================================
16sub encode {
17#===================================
18 my ( $self, $var ) = @_;
19 unless ( ref $var ) {
20 return is_utf8($var)
21 ? encode_utf8($var)
22 : $var;
23 }
24 return try { $self->JSON->encode($var) }
25 catch { throw( "Serializer", $_, { var => $var } ) };
26}
27
28#===================================
29sub encode_bulk {
30#===================================
31 my ( $self, $var ) = @_;
32 unless ( ref $var ) {
33 return is_utf8($var)
34 ? encode_utf8($var)
35 : $var;
36 }
37
38 my $json = '';
39 throw( "Param", "Var must be an array ref" )
40 unless ref $var eq 'ARRAY';
41 return try {
42 for (@$var) {
43 $json .= ( ref($_) ? $self->JSON->encode($_) : $_ ) . "\n";
44 }
45 return $json;
46 }
47 catch { throw( "Serializer", $_, { var => $var } ) };
48}
49
50#===================================
51sub encode_pretty {
52#===================================
53 my ( $self, $var ) = @_;
54 $self->JSON->pretty(1);
55
56 my $json;
57 try {
58 $json = $self->encode($var);
59 }
60 catch {
61 die "$_";
62 }
63 finally {
64 $self->JSON->pretty(0);
65 };
66
67 return $json;
68}
69
70#===================================
71sub decode {
72#===================================
73 my ( $self, $json ) = @_;
74
75 return unless defined $json;
76
77 return is_utf8($json) ? $json : decode_utf8($json)
78 unless substr( $json, 0, 1 ) =~ /^[\[{]/;
79
80 return try {
81 $self->JSON->decode($json);
82 }
83 catch {
84 throw( "Serializer", $_, { json => $json } );
85 };
86}
87
88#===================================
89sub _set_canonical {
90#===================================
91 shift()->JSON->canonical(1);
92}
93
9417µs1;
95
96=pod
97
98=encoding UTF-8
99
100=head1 NAME
101
102Search::Elasticsearch::Role::Serializer::JSON - A Serializer role for JSON modules
103
104=head1 VERSION
105
106version 2.02
107
108=head1 DESCRIPTION
109
110This role encodes Perl data structures into JSON strings, and
111decodes JSON strings into Perl data structures.
112
113=head1 METHODS
114
115=head2 C<encode()>
116
117 $bytes = $serializer->encode($ref);
118 $bytes = $serializer->encode($str);
119
120The L</encode()> method converts array and hash refs into their JSON
121equivalents. If a string is passed in, it is returned as the UTF8 encoded
122version of itself. The empty string and C<undef> are returned as is.
123
124=head2 C<encode_pretty()>
125
126 $bytes = $serializer->encode_pretty($ref);
127 $bytes = $serializer->encode_pretty($str);
128
129Works exactly as L</encode()> but the JSON output is pretty-printed.
130
131=head2 C<encode_bulk()>
132
133 $bytes = $serializer->encode_bulk([\%hash,\%hash,...]);
134 $bytes = $serializer->encode_bulk([$str,$str,...]);
135
136The L</encode_bulk()> method expects an array ref of hashes or strings.
137Each hash or string is processed by L</encode()> then joined together
138by newline characters, with a final newline character appended to the end.
139This is the special JSON format used for bulk requests.
140
141=head2 C<decode()>
142
143 $var = $serializer->decode($json_bytes);
144 $str = $serializer->decode($bytes);
145
146If the passed in value looks like JSON (ie starts with a C<{> or C<[>
147character), then it is decoded from JSON, otherwise it is returned as
148the UTF8 decoded version of itself. The empty string and C<undef> are
149returned as is.
150
151=head1 AUTHOR
152
153Clinton Gormley <drtech@cpan.org>
154
155=head1 COPYRIGHT AND LICENSE
156
157This software is Copyright (c) 2016 by Elasticsearch BV.
158
159This is free software, licensed under:
160
161 The Apache License, Version 2.0, January 2004
162
163=cut
164
165114µs1535µs__END__