| Filename | /usr/libdata/perl5/OpenBSD/Subst.pm |
| Statements | Executed 14 statements in 1.80ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 31µs | 40µs | OpenBSD::State::BEGIN@18 |
| 4 | 2 | 2 | 26µs | 26µs | OpenBSD::Subst::value |
| 1 | 1 | 1 | 18µs | 38µs | OpenBSD::State::BEGIN@19 |
| 1 | 1 | 1 | 3µs | 3µs | OpenBSD::Subst::new |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Subst::add |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Subst::copy |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Subst::copy_fh |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Subst::copy_fh2 |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Subst::do |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Subst::empty |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Subst::has_fragment |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Subst::hash |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Subst::parse_option |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # ex:ts=8 sw=4: | ||||
| 2 | # $OpenBSD: Subst.pm,v 1.17 2016/06/21 10:40:37 espie Exp $ | ||||
| 3 | # | ||||
| 4 | # Copyright (c) 2008 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 | 2 | 52µs | 2 | 48µs | # spent 40µs (31+8) within OpenBSD::State::BEGIN@18 which was called:
# once (31µs+8µs) by OpenBSD::State::BEGIN@87 at line 18 # spent 40µs making 1 call to OpenBSD::State::BEGIN@18
# spent 8µs making 1 call to strict::import |
| 19 | 2 | 1.71ms | 2 | 58µs | # spent 38µs (18+20) within OpenBSD::State::BEGIN@19 which was called:
# once (18µs+20µs) by OpenBSD::State::BEGIN@87 at line 19 # spent 38µs making 1 call to OpenBSD::State::BEGIN@19
# spent 20µs making 1 call to warnings::import |
| 20 | |||||
| 21 | # very simple package, just holds everything needed for substitution | ||||
| 22 | # according to package rules. | ||||
| 23 | |||||
| 24 | package OpenBSD::Subst; | ||||
| 25 | |||||
| 26 | sub new | ||||
| 27 | # spent 3µs within OpenBSD::Subst::new which was called:
# once (3µs+0s) by OpenBSD::State::init at line 111 of OpenBSD/State.pm | ||||
| 28 | 1 | 7µs | bless {}, shift; | ||
| 29 | } | ||||
| 30 | |||||
| 31 | sub hash | ||||
| 32 | { | ||||
| 33 | shift; | ||||
| 34 | } | ||||
| 35 | |||||
| 36 | sub add | ||||
| 37 | { | ||||
| 38 | my ($self, $k, $v) = @_; | ||||
| 39 | $k =~ s/^\^//; | ||||
| 40 | $self->{$k} = $v; | ||||
| 41 | } | ||||
| 42 | |||||
| 43 | sub value | ||||
| 44 | # spent 26µs within OpenBSD::Subst::value which was called 4 times, avg 7µs/call:
# 3 times (24µs+0s) by OpenBSD::State::defines at line 313 of OpenBSD/State.pm, avg 8µs/call
# once (2µs+0s) by OpenBSD::PkgInfo::State::lock at line 71 of OpenBSD/PkgInfo.pm | ||||
| 45 | 4 | 5µs | my ($self, $k) = @_; | ||
| 46 | 4 | 17µs | return $self->{$k}; | ||
| 47 | } | ||||
| 48 | |||||
| 49 | sub parse_option | ||||
| 50 | { | ||||
| 51 | my ($self, $opt) = @_; | ||||
| 52 | if ($opt =~ m/^([^=]+)\=(.*)$/o) { | ||||
| 53 | my ($k, $v) = ($1, $2); | ||||
| 54 | $v =~ s/^\'(.*)\'$/$1/; | ||||
| 55 | $v =~ s/^\"(.*)\"$/$1/; | ||||
| 56 | $self->add($k, $v); | ||||
| 57 | } else { | ||||
| 58 | $self->add($opt, 1); | ||||
| 59 | } | ||||
| 60 | } | ||||
| 61 | |||||
| 62 | sub do | ||||
| 63 | { | ||||
| 64 | my $self = shift; | ||||
| 65 | my $s = shift; | ||||
| 66 | return $s unless $s =~ m/\$/o; # optimization | ||||
| 67 | while ( my $k = ($s =~ m/\$\{([A-Za-z_][^\}]*)\}/o)[0] ) { | ||||
| 68 | my $v = $self->{$k}; | ||||
| 69 | unless ( defined $v ) { $v = "\$\\\{$k\}"; } | ||||
| 70 | $s =~ s/\$\{\Q$k\E\}/$v/g; | ||||
| 71 | } | ||||
| 72 | $s =~ s/\$\\\{([A-Za-z_])/\$\{$1/go; | ||||
| 73 | return $s; | ||||
| 74 | } | ||||
| 75 | |||||
| 76 | sub copy_fh2 | ||||
| 77 | { | ||||
| 78 | my ($self, $src, $dest) = @_; | ||||
| 79 | my $contents = do { local $/; <$src> }; | ||||
| 80 | while (my ($k, $v) = each %{$self}) { | ||||
| 81 | $contents =~ s/\$\{\Q$k\E\}/$v/g; | ||||
| 82 | } | ||||
| 83 | $contents =~ s/\$\\\{([A-Za-z_])/\$\{$1/go; | ||||
| 84 | print $dest $contents; | ||||
| 85 | } | ||||
| 86 | |||||
| 87 | sub copy_fh | ||||
| 88 | { | ||||
| 89 | my ($self, $srcname, $dest) = @_; | ||||
| 90 | open my $src, '<', $srcname or die "can't open $srcname"; | ||||
| 91 | $self->copy_fh2($src, $dest); | ||||
| 92 | } | ||||
| 93 | |||||
| 94 | sub copy | ||||
| 95 | { | ||||
| 96 | my ($self, $srcname, $destname) = @_; | ||||
| 97 | open my $dest, '>', $destname or die "can't open $destname"; | ||||
| 98 | $self->copy_fh($srcname, $dest); | ||||
| 99 | return $dest; | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | sub has_fragment | ||||
| 103 | { | ||||
| 104 | my ($self, $def, $frag, $msg) = @_; | ||||
| 105 | |||||
| 106 | my $v = $self->value($def); | ||||
| 107 | |||||
| 108 | if (!defined $v) { | ||||
| 109 | die "Error: unknown fragment $frag in $msg"; | ||||
| 110 | } elsif ($v == 1) { | ||||
| 111 | return 1; | ||||
| 112 | } elsif ($v == 0) { | ||||
| 113 | return 0; | ||||
| 114 | } else { | ||||
| 115 | die "Incorrect define for $frag in $msg"; | ||||
| 116 | } | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | sub empty | ||||
| 120 | { | ||||
| 121 | my ($self, $k) = @_; | ||||
| 122 | |||||
| 123 | my $v = $self->value($k); | ||||
| 124 | if (defined $v && $v) { | ||||
| 125 | return 0; | ||||
| 126 | } else { | ||||
| 127 | return 1; | ||||
| 128 | } | ||||
| 129 | } | ||||
| 130 | |||||
| 131 | 1 | 6µs | 1; |