| Filename | /usr/libdata/perl5/OpenBSD/Getopt.pm |
| Statements | Executed 34 statements in 542µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 65µs | 181µs | OpenBSD::Getopt::getopts |
| 1 | 1 | 1 | 17µs | 21µs | OpenBSD::PkgInfo::BEGIN@21 |
| 1 | 1 | 1 | 16µs | 25µs | OpenBSD::PkgInfo::BEGIN@22 |
| 1 | 1 | 1 | 12µs | 12µs | OpenBSD::Getopt::handle_option |
| 1 | 1 | 1 | 10µs | 10µs | OpenBSD::Getopt::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 9µs | 28µs | OpenBSD::Getopt::BEGIN@37 |
| 1 | 1 | 1 | 8µs | 25µs | OpenBSD::Getopt::BEGIN@38 |
| 3 | 3 | 1 | 6µs | 6µs | OpenBSD::Getopt::CORE:match (opcode) |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # ex:ts=8 sw=4: | ||||
| 2 | # $OpenBSD: Getopt.pm,v 1.12 2012/04/10 16:57:12 espie Exp $ | ||||
| 3 | # | ||||
| 4 | # Copyright (c) 2006 Marc Espie <espie@openbsd.org> | ||||
| 5 | # | ||||
| 6 | # Permission to use, copy, modify, and distribute this software for any | ||||
| 7 | # purpose with or without fee is hereby granted, provided that the above | ||||
| 8 | # copyright notice and this permission notice appear in all copies. | ||||
| 9 | # | ||||
| 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||
| 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||
| 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||
| 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||
| 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||
| 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||
| 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||
| 17 | # | ||||
| 18 | # This is inspired by Getopt::Std, except for the ability to invoke subs | ||||
| 19 | # on options. | ||||
| 20 | |||||
| 21 | 2 | 30µs | 2 | 25µs | # spent 21µs (17+4) within OpenBSD::PkgInfo::BEGIN@21 which was called:
# once (17µs+4µs) by OpenBSD::PkgInfo::BEGIN@179 at line 21 # spent 21µs making 1 call to OpenBSD::PkgInfo::BEGIN@21
# spent 4µs making 1 call to strict::import |
| 22 | 2 | 81µs | 2 | 34µs | # spent 25µs (16+9) within OpenBSD::PkgInfo::BEGIN@22 which was called:
# once (16µs+9µs) by OpenBSD::PkgInfo::BEGIN@179 at line 22 # spent 25µs making 1 call to OpenBSD::PkgInfo::BEGIN@22
# spent 9µs making 1 call to warnings::import |
| 23 | |||||
| 24 | package OpenBSD::Getopt; | ||||
| 25 | 1 | 1µs | require Exporter; | ||
| 26 | |||||
| 27 | 1 | 6µs | our @ISA = qw(Exporter); | ||
| 28 | 1 | 1µs | our @EXPORT = qw(getopts); | ||
| 29 | |||||
| 30 | sub handle_option | ||||
| 31 | # spent 12µs within OpenBSD::Getopt::handle_option which was called:
# once (12µs+0s) by OpenBSD::Getopt::getopts at line 71 | ||||
| 32 | 1 | 1µs | my ($opt, $hash, $params) = @_; | ||
| 33 | |||||
| 34 | 1 | 8µs | if (defined $hash->{$opt} and ref($hash->{$opt}) eq 'CODE') { | ||
| 35 | &{$hash->{$opt}}($params); | ||||
| 36 | } else { | ||||
| 37 | 2 | 35µs | 2 | 48µs | # spent 28µs (9+19) within OpenBSD::Getopt::BEGIN@37 which was called:
# once (9µs+19µs) by OpenBSD::PkgInfo::BEGIN@179 at line 37 # spent 28µs making 1 call to OpenBSD::Getopt::BEGIN@37
# spent 19µs making 1 call to strict::unimport |
| 38 | 2 | 292µs | 2 | 41µs | # spent 25µs (8+16) within OpenBSD::Getopt::BEGIN@38 which was called:
# once (8µs+16µs) by OpenBSD::PkgInfo::BEGIN@179 at line 38 # spent 25µs making 1 call to OpenBSD::Getopt::BEGIN@38
# spent 16µs making 1 call to strict::unimport |
| 39 | |||||
| 40 | 1 | 1µs | if (defined $params) { | ||
| 41 | 1 | 3µs | ${"opt_$opt"} = $params; | ||
| 42 | 1 | 1µs | $hash->{$opt} = $params; | ||
| 43 | } else { | ||||
| 44 | ${"opt_$opt"}++; | ||||
| 45 | $hash->{$opt}++; | ||||
| 46 | } | ||||
| 47 | 1 | 1µs | push(@EXPORT, "\$opt_$opt"); | ||
| 48 | } | ||||
| 49 | } | ||||
| 50 | |||||
| 51 | sub getopts($;$) | ||||
| 52 | # spent 181µs (65+116) within OpenBSD::Getopt::getopts which was called:
# once (65µs+116µs) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:287] at line 286 of OpenBSD/State.pm | ||||
| 53 | 1 | 700ns | my ($args, $hash) = @_; | ||
| 54 | |||||
| 55 | 1 | 800ns | $hash = {} unless defined $hash; | ||
| 56 | 1 | 9µs | local @EXPORT; | ||
| 57 | |||||
| 58 | 1 | 2µs | while ($_ = shift @ARGV) { | ||
| 59 | 1 | 7µs | 1 | 1µs | last if /^--$/o; # spent 1µs making 1 call to OpenBSD::Getopt::CORE:match |
| 60 | 1 | 6µs | 1 | 2µs | unless (m/^-(.)(.*)/so) { # spent 2µs making 1 call to OpenBSD::Getopt::CORE:match |
| 61 | unshift @ARGV, $_; | ||||
| 62 | last; | ||||
| 63 | } | ||||
| 64 | 1 | 2µs | my ($opt, $other) = ($1, $2); | ||
| 65 | 1 | 23µs | 2 | 12µs | if ($args =~ m/\Q$opt\E(\:?)/) { # spent 10µs making 1 call to OpenBSD::Getopt::CORE:regcomp
# spent 2µs making 1 call to OpenBSD::Getopt::CORE:match |
| 66 | 1 | 2µs | if ($1 eq ':') { | ||
| 67 | 1 | 2µs | if ($other eq '') { | ||
| 68 | 1 | 800ns | die "no argument for option -$opt" unless @ARGV; | ||
| 69 | 1 | 1µs | $other = shift @ARGV; | ||
| 70 | } | ||||
| 71 | 1 | 3µs | 1 | 12µs | handle_option($opt, $hash, $other); # spent 12µs making 1 call to OpenBSD::Getopt::handle_option |
| 72 | } else { | ||||
| 73 | handle_option($opt, $hash); | ||||
| 74 | if ($other ne '') { | ||||
| 75 | $_ = "-$other"; | ||||
| 76 | redo; | ||||
| 77 | } | ||||
| 78 | } | ||||
| 79 | } else { | ||||
| 80 | delete $SIG{__DIE__}; | ||||
| 81 | die "Unknown option -$opt"; | ||||
| 82 | } | ||||
| 83 | } | ||||
| 84 | 1 | 9µs | local $Exporter::ExportLevel = 1; | ||
| 85 | 1 | 3µs | 1 | 89µs | import OpenBSD::Getopt; # spent 89µs making 1 call to Exporter::import |
| 86 | 1 | 4µs | return $hash; | ||
| 87 | } | ||||
| 88 | |||||
| 89 | 1 | 5µs | 1; | ||
sub OpenBSD::Getopt::CORE:match; # opcode | |||||
# spent 10µs within OpenBSD::Getopt::CORE:regcomp which was called:
# once (10µs+0s) by OpenBSD::Getopt::getopts at line 65 |