← Index
NYTProf Performance Profile   « line view »
For /usr/sbin/pkg_info
  Run on Fri Aug 4 10:12:01 2017
Reported on Fri Aug 4 10:12:17 2017

Filename/usr/libdata/perl5/OpenBSD/Subst.pm
StatementsExecuted 14 statements in 1.80ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11131µs40µsOpenBSD::State::::BEGIN@18OpenBSD::State::BEGIN@18
42226µs26µsOpenBSD::Subst::::valueOpenBSD::Subst::value
11118µs38µsOpenBSD::State::::BEGIN@19OpenBSD::State::BEGIN@19
1113µs3µsOpenBSD::Subst::::newOpenBSD::Subst::new
0000s0sOpenBSD::Subst::::addOpenBSD::Subst::add
0000s0sOpenBSD::Subst::::copyOpenBSD::Subst::copy
0000s0sOpenBSD::Subst::::copy_fhOpenBSD::Subst::copy_fh
0000s0sOpenBSD::Subst::::copy_fh2OpenBSD::Subst::copy_fh2
0000s0sOpenBSD::Subst::::doOpenBSD::Subst::do
0000s0sOpenBSD::Subst::::emptyOpenBSD::Subst::empty
0000s0sOpenBSD::Subst::::has_fragmentOpenBSD::Subst::has_fragment
0000s0sOpenBSD::Subst::::hashOpenBSD::Subst::hash
0000s0sOpenBSD::Subst::::parse_optionOpenBSD::Subst::parse_option
Call graph for these subroutines as a Graphviz dot language file.
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
18252µs248µ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
use strict;
# spent 40µs making 1 call to OpenBSD::State::BEGIN@18 # spent 8µs making 1 call to strict::import
1921.71ms258µ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
use warnings;
# 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
24package OpenBSD::Subst;
25
26sub 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
{
2817µs bless {}, shift;
29}
30
31sub hash
32{
33 shift;
34}
35
36sub add
37{
38 my ($self, $k, $v) = @_;
39 $k =~ s/^\^//;
40 $self->{$k} = $v;
41}
42
43sub 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
{
4545µs my ($self, $k) = @_;
46417µs return $self->{$k};
47}
48
49sub 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
62sub 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
76sub 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
87sub 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
94sub 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
102sub 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
119sub 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
13116µs1;