Filename | /home/mickey/git_tree/PONAPI/Server/lib/PONAPI/CLI/Command/demo.pm |
Statements | Executed 20 statements in 458µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 17µs | 176µs | BEGIN@4 | PONAPI::CLI::Command::demo::
1 | 1 | 1 | 12µs | 12µs | validate_args | PONAPI::CLI::Command::demo::
1 | 1 | 1 | 7µs | 18µs | BEGIN@6 | PONAPI::CLI::Command::demo::
1 | 1 | 1 | 6µs | 12µs | BEGIN@7 | PONAPI::CLI::Command::demo::
1 | 1 | 1 | 4µs | 4µs | opt_spec | PONAPI::CLI::Command::demo::
0 | 0 | 0 | 0s | 0s | abstract | PONAPI::CLI::Command::demo::
0 | 0 | 0 | 0s | 0s | description | PONAPI::CLI::Command::demo::
0 | 0 | 0 | 0s | 0s | execute | PONAPI::CLI::Command::demo::
0 | 0 | 0 | 0s | 0s | run_query | PONAPI::CLI::Command::demo::
0 | 0 | 0 | 0s | 0s | run_server | PONAPI::CLI::Command::demo::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # ABSTRACT: ponapi demo running command line utility | ||||
2 | package PONAPI::CLI::Command::demo; | ||||
3 | |||||
4 | 2 | 30µs | 2 | 335µs | # spent 176µs (17+159) within PONAPI::CLI::Command::demo::BEGIN@4 which was called:
# once (17µs+159µs) by Module::Runtime::require_module at line 4 # spent 176µs making 1 call to PONAPI::CLI::Command::demo::BEGIN@4
# spent 159µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
5 | |||||
6 | 2 | 20µs | 2 | 29µs | # spent 18µs (7+11) within PONAPI::CLI::Command::demo::BEGIN@6 which was called:
# once (7µs+11µs) by Module::Runtime::require_module at line 6 # spent 18µs making 1 call to PONAPI::CLI::Command::demo::BEGIN@6
# spent 11µs making 1 call to strict::import |
7 | 2 | 284µs | 2 | 18µs | # spent 12µs (6+6) within PONAPI::CLI::Command::demo::BEGIN@7 which was called:
# once (6µs+6µs) by Module::Runtime::require_module at line 7 # spent 12µs making 1 call to PONAPI::CLI::Command::demo::BEGIN@7
# spent 6µs making 1 call to warnings::import |
8 | |||||
9 | sub abstract { "Run a DEMO PONAPI server" } | ||||
10 | sub description { "This tool will run a demo server with a mock DB" } | ||||
11 | |||||
12 | # spent 4µs within PONAPI::CLI::Command::demo::opt_spec which was called:
# once (4µs+0s) by App::Cmd::Command::_option_processing_params at line 44 of App/Cmd/Command.pm | ||||
13 | return ( | ||||
14 | 1 | 5µs | [ "s|server", "Run a local PONAPI demo server" ], | ||
15 | [ "q|query:s", "Send a random/provided query to local server" ], | ||||
16 | [ "p|port=i", "Specify a port for the server (default=5000)" ], | ||||
17 | [ "j|json", "JSON-only output" ], | ||||
18 | ); | ||||
19 | } | ||||
20 | |||||
21 | # spent 12µs within PONAPI::CLI::Command::demo::validate_args which was called:
# once (12µs+0s) by App::Cmd::execute_command at line 467 of App/Cmd.pm | ||||
22 | 1 | 400ns | my ( $self, $opt, $args ) = @_; | ||
23 | |||||
24 | 1 | 5µs | $self->usage_error("(only) one of server (-s) or query (-q [STR]) is required.\n") | ||
25 | unless exists $opt->{s} xor exists $opt->{q}; | ||||
26 | |||||
27 | 1 | 3µs | $self->{port} = $opt->{port} || $opt->{p} || 5000; | ||
28 | |||||
29 | 1 | 700ns | $self->{query_string} = ""; | ||
30 | |||||
31 | 1 | 600ns | if ( exists $opt->{q} and $opt->{q} ) { | ||
32 | $opt->{q} =~ s|^/||; | ||||
33 | $self->{query_string} = | ||||
34 | ( $opt->{q} !~ /^http/ ? 'http://localhost:' . $self->{port} . '/' : '' ) | ||||
35 | . $opt->{q}; | ||||
36 | |||||
37 | } | ||||
38 | |||||
39 | 1 | 1µs | $self->{only_json} = !!( $opt->{json} || $opt->{j} ); | ||
40 | 1 | 4µs | $self->usage_error("JSON-only works just in Query mode") | ||
41 | if $self->{only_json} and !exists $opt->{q}; | ||||
42 | } | ||||
43 | |||||
44 | sub execute { | ||||
45 | 1 | 400ns | my ( $self, $opt, $args ) = @_; | ||
46 | |||||
47 | 1 | 2µs | $self->run_server() if exists $opt->{s}; | ||
48 | $self->run_query() if exists $opt->{q}; | ||||
49 | } | ||||
50 | |||||
51 | sub run_server { | ||||
52 | 1 | 300ns | my $self = shift; | ||
53 | 1 | 97µs | require PONAPI::CLI::RunServer; | ||
54 | 1 | 2µs | PONAPI::CLI::RunServer::run( $self->{port} ); | ||
55 | } | ||||
56 | |||||
57 | sub run_query { | ||||
58 | my $self = shift; | ||||
59 | require PONAPI::CLI::RunQuery; | ||||
60 | PONAPI::CLI::RunQuery::run( $self->{port}, $self->{query_string}, $self->{only_json} ); | ||||
61 | } | ||||
62 | |||||
63 | 1 | 2µs | 1; |