← 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/Util/API/Path.pm
StatementsExecuted 34 statements in 642µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111323µs572µsSearch::Elasticsearch::Util::API::Path::::BEGIN@5Search::Elasticsearch::Util::API::Path::BEGIN@5
11125µs53µsSearch::Elasticsearch::Util::API::Path::::path_handlerSearch::Elasticsearch::Util::API::Path::path_handler
11116µs30µsSearch::Elasticsearch::Util::API::Path::::BEGIN@3Search::Elasticsearch::Util::API::Path::BEGIN@3
11111µs23µsSearch::Elasticsearch::Util::API::Path::::BEGIN@18Search::Elasticsearch::Util::API::Path::BEGIN@18
11111µs249µsSearch::Elasticsearch::Util::API::Path::::BEGIN@7Search::Elasticsearch::Util::API::Path::BEGIN@7
1119µs14µsSearch::Elasticsearch::Util::API::Path::::BEGIN@4Search::Elasticsearch::Util::API::Path::BEGIN@4
1119µs147µsSearch::Elasticsearch::Util::API::Path::::BEGIN@6Search::Elasticsearch::Util::API::Path::BEGIN@6
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::Util::API::Path;
211µs$Search::Elasticsearch::Util::API::Path::VERSION = '2.02';
3231µs244µs
# spent 30µs (16+14) within Search::Elasticsearch::Util::API::Path::BEGIN@3 which was called: # once (16µs+14µs) by Search::Elasticsearch::Role::Client::Direct::BEGIN@5 at line 3
use strict;
# spent 30µs making 1 call to Search::Elasticsearch::Util::API::Path::BEGIN@3 # spent 14µs making 1 call to strict::import
4229µs219µs
# spent 14µs (9+5) within Search::Elasticsearch::Util::API::Path::BEGIN@4 which was called: # once (9µs+5µs) by Search::Elasticsearch::Role::Client::Direct::BEGIN@5 at line 4
use warnings;
# spent 14µs making 1 call to Search::Elasticsearch::Util::API::Path::BEGIN@4 # spent 5µs making 1 call to warnings::import
52114µs2614µs
# spent 572µs (323+249) within Search::Elasticsearch::Util::API::Path::BEGIN@5 which was called: # once (323µs+249µs) by Search::Elasticsearch::Role::Client::Direct::BEGIN@5 at line 5
use Any::URI::Escape qw(uri_escape);
# spent 572µs making 1 call to Search::Elasticsearch::Util::API::Path::BEGIN@5 # spent 42µs making 1 call to Exporter::import
6243µs2285µs
# spent 147µs (9+138) within Search::Elasticsearch::Util::API::Path::BEGIN@6 which was called: # once (9µs+138µs) by Search::Elasticsearch::Role::Client::Direct::BEGIN@5 at line 6
use Search::Elasticsearch::Util qw(throw);
7280µs2487µs
# spent 249µs (11+238) within Search::Elasticsearch::Util::API::Path::BEGIN@7 which was called: # once (11µs+238µs) by Search::Elasticsearch::Role::Client::Direct::BEGIN@5 at line 7
use Sub::Exporter -setup => { exports => ['path_handler'] };
8
9#===================================
10
# spent 53µs (25+28) within Search::Elasticsearch::Util::API::Path::path_handler which was called: # once (25µs+28µs) by Search::Elasticsearch::Role::Client::Direct::_parse_path at line 46 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/Client/Direct.pm
sub path_handler {
11#===================================
121300ns my ( $defn, $params ) = @_;
131400ns my $paths = $defn->{paths};
141300ns my $parts = $defn->{parts};
15
161200ns my %args;
171600ns keys %$parts;
182313µs234µs
# spent 23µs (11+12) within Search::Elasticsearch::Util::API::Path::BEGIN@18 which was called: # once (11µs+12µs) by Search::Elasticsearch::Role::Client::Direct::BEGIN@5 at line 18
no warnings 'uninitialized';
# spent 23µs making 1 call to Search::Elasticsearch::Util::API::Path::BEGIN@18 # spent 12µs making 1 call to warnings::unimport
1913µs while ( my ( $key, $req ) = each %$parts ) {
201800ns my $val = delete $params->{$key};
211400ns if ( ref $val eq 'ARRAY' ) {
22 die "Param ($key) must contain a single value\n"
23 if @$val > 1 and not $req->{multi};
24 $val = join ",", @$val;
25 }
261400ns if ( !length $val ) {
27 die "Missing required param ($key)\n"
28 if $req->{required};
29 next;
30 }
3116µs11µs utf8::encode($val);
# spent 1µs making 1 call to utf8::encode
3212µs127µs $args{$key} = uri_escape($val);
# spent 27µs making 1 call to URI::Escape::uri_escape
33 }
341600nsPATH: for my $path (@$paths) {
3512µs my @keys = keys %{ $path->[0] };
361700ns next PATH unless @keys == keys %args;
371600ns for (@keys) {
3811µs next PATH unless exists $args{$_};
39 }
401600ns my ( $pos, @parts ) = @$path;
411800ns for ( keys %$pos ) {
4211µs $parts[ $pos->{$_} ] = $args{$_};
43 }
4416µs return join "/", '', @parts;
45 }
46
47 die "Param (index) required when (type) specified\n"
48 if $defn->{index_when_type} && $args{type} && !$args{index};
49
50 throw(
51 'Internal',
52 "Couldn't determine path",
53 { params => $params, defn => $defn }
54 );
55}
56
5713µs1;
58
59=pod
60
61=encoding UTF-8
62
63=head1 NAME
64
65Search::Elasticsearch::Util::API::Path - A utility class for converting path templates into real paths
66
67=head1 VERSION
68
69version 2.02
70
71=head1 DESCRIPTION
72
73This module converts path templates in L<Search::Elasticsearch::Role::API> such as
74C</{index}/{type}/{id}> into real paths such as C</my_index/my_type/123>.
75
76=head1 EXPORTS
77
78=head2 C<path_init()>
79
80 use Search::Elasticsearch::Util::API::Path qw(path_init);
81
82 $handler = path_init($template);
83 $path = $handler->(\%params);
84
85The C<path_init()> sub accepts a path template and returns an anonymous sub
86which converts C<\%params> into a real path, removing the keys that it
87has used from C<%params>, eg:
88
89 $handler = path_init('/{indices}/_search');
90 $params = { index => ['foo','bar'], size => 10 };
91 $path = $handler->($params);
92
93Would result in:
94
95 $path: '/foo,bar/_search';
96 $params: { size => 10 };
97
98=head1 AUTHOR
99
100Clinton Gormley <drtech@cpan.org>
101
102=head1 COPYRIGHT AND LICENSE
103
104This software is Copyright (c) 2016 by Elasticsearch BV.
105
106This is free software, licensed under:
107
108 The Apache License, Version 2.0, January 2004
109
110=cut
111
112__END__