← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/Text/Wrap.pm
StatementsExecuted 28 statements in 948µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111554µs687µsText::Wrap::::BEGIN@35Text::Wrap::BEGIN@35
11115µs111µsText::Wrap::::BEGIN@3Text::Wrap::BEGIN@3
11113µs13µsText::Wrap::::BEGIN@13Text::Wrap::BEGIN@13
11110µs26µsText::Wrap::::BEGIN@58Text::Wrap::BEGIN@58
1119µs114µsText::Wrap::::BEGIN@15Text::Wrap::BEGIN@15
1118µs23µsText::Wrap::::BEGIN@16Text::Wrap::BEGIN@16
1114µs4µsText::Wrap::::BEGIN@18Text::Wrap::BEGIN@18
1112µs2µsText::Wrap::::CORE:qrText::Wrap::CORE:qr (opcode)
0000s0sText::Wrap::::_xlenText::Wrap::_xlen
0000s0sText::Wrap::::_xposText::Wrap::_xpos
0000s0sText::Wrap::::fillText::Wrap::fill
0000s0sText::Wrap::::wrapText::Wrap::wrap
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Text::Wrap;
2
3263µs2206µs
# spent 111µs (15+95) within Text::Wrap::BEGIN@3 which was called: # once (15µs+95µs) by Pod::Spell::BEGIN@12 at line 3
use warnings::register;
# spent 111µs making 1 call to Text::Wrap::BEGIN@3 # spent 95µs making 1 call to warnings::register::import
41300nsrequire Exporter;
5
615µs@ISA = qw(Exporter);
71700ns@EXPORT = qw(wrap fill);
81500ns@EXPORT_OK = qw($columns $break $huge);
9
101200ns$VERSION = 2012.0818;
111200ns$SUBVERSION = 'modern';
12
13244µs113µs
# spent 13µs within Text::Wrap::BEGIN@13 which was called: # once (13µs+0s) by Pod::Spell::BEGIN@12 at line 13
use 5.010_000;
# spent 13µs making 1 call to Text::Wrap::BEGIN@13
14
15224µs2219µs
# spent 114µs (9+105) within Text::Wrap::BEGIN@15 which was called: # once (9µs+105µs) by Pod::Spell::BEGIN@12 at line 15
use vars qw($VERSION $SUBVERSION $columns $debug $break $huge $unexpand $tabstop $separator $separator2);
# spent 114µs making 1 call to Text::Wrap::BEGIN@15 # spent 105µs making 1 call to vars::import
16253µs239µs
# spent 23µs (8+15) within Text::Wrap::BEGIN@16 which was called: # once (8µs+15µs) by Pod::Spell::BEGIN@12 at line 16
use strict;
# spent 23µs making 1 call to Text::Wrap::BEGIN@16 # spent 15µs making 1 call to strict::import
17
18
# spent 4µs within Text::Wrap::BEGIN@18 which was called: # once (4µs+0s) by Pod::Spell::BEGIN@12 at line 27
BEGIN {
191200ns $columns = 76; # <= screen width
2010s $debug = 0;
211200ns $break = '(?=\s)\X';
221100ns $huge = 'wrap'; # alternatively: 'die' or 'overflow'
2310s $unexpand = 1;
2410s $tabstop = 8;
251100ns $separator = "\n";
2614µs $separator2 = undef;
271122µs14µs}
# spent 4µs making 1 call to Text::Wrap::BEGIN@18
28
2918µs12µsmy $CHUNK = qr/\X/;
# spent 2µs making 1 call to Text::Wrap::CORE:qr
30
31sub _xlen(_) { scalar(() = $_[0] =~ /$CHUNK/g) }
32
33sub _xpos(_) { _xlen( substr( $_[0], 0, pos($_[0]) ) ) }
34
352262µs2733µs
# spent 687µs (554+133) within Text::Wrap::BEGIN@35 which was called: # once (554µs+133µs) by Pod::Spell::BEGIN@12 at line 35
use Text::Tabs qw(expand unexpand);
# spent 687µs making 1 call to Text::Wrap::BEGIN@35 # spent 45µs making 1 call to Exporter::import
36
37sub wrap
38{
39 my ($ip, $xp, @t) = @_;
40
41 local($Text::Tabs::tabstop) = $tabstop;
42 my $r = "";
43 my $tail = pop(@t);
44 my $t = expand(join("", (map { /\s+\z/ ? ( $_ ) : ($_, ' ') } @t), $tail));
45 my $lead = $ip;
46 my $nll = $columns - _xlen(expand($xp)) - 1;
47 if ($nll <= 0 && $xp ne '') {
48 my $nc = _xlen(expand($xp)) + 2;
49 warnings::warnif "Increasing \$Text::Wrap::columns from $columns to $nc to accommodate length of subsequent tab";
50 $columns = $nc;
51 $nll = 1;
52 }
53 my $ll = $columns - _xlen(expand($ip)) - 1;
54 $ll = 0 if $ll < 0;
55 my $nl = "";
56 my $remainder = "";
57
582356µs241µs
# spent 26µs (10+15) within Text::Wrap::BEGIN@58 which was called: # once (10µs+15µs) by Pod::Spell::BEGIN@12 at line 58
use re 'taint';
# spent 26µs making 1 call to Text::Wrap::BEGIN@58 # spent 16µs making 1 call to re::import
59
60 pos($t) = 0;
61 while ($t !~ /\G(?:$break)*\Z/gc) {
62 if ($t =~ /\G((?:(?=[^\n])\X){0,$ll})($break|\n+|\z)/xmgc) {
63 $r .= $unexpand
64 ? unexpand($nl . $lead . $1)
65 : $nl . $lead . $1;
66 $remainder = $2;
67 } elsif ($huge eq 'wrap' && $t =~ /\G((?:(?!=[^\n])\X){$ll})/gc) {
68 $r .= $unexpand
69 ? unexpand($nl . $lead . $1)
70 : $nl . $lead . $1;
71 $remainder = defined($separator2) ? $separator2 : $separator;
72 } elsif ($huge eq 'overflow' && $t =~ /\G((?:(?=[^\n])\X)*?)($break|\n+|\z)/xmgc) {
73 $r .= $unexpand
74 ? unexpand($nl . $lead . $1)
75 : $nl . $lead . $1;
76 $remainder = $2;
77 } elsif ($huge eq 'die') {
78 die "couldn't wrap '$t'";
79 } elsif ($columns < 2) {
80 warnings::warnif "Increasing \$Text::Wrap::columns from $columns to 2";
81 $columns = 2;
82 return ($ip, $xp, @t);
83 } else {
84 die "This shouldn't happen";
85 }
86
87 $lead = $xp;
88 $ll = $nll;
89 $nl = defined($separator2)
90 ? ($remainder eq "\n"
91 ? "\n"
92 : $separator2)
93 : $separator;
94 }
95 $r .= $remainder;
96
97 print "-----------$r---------\n" if $debug;
98
99 print "Finish up with '$lead'\n" if $debug;
100
101 my($opos) = pos($t);
102
103 $r .= $lead . substr($t, pos($t), length($t) - pos($t))
104 if pos($t) ne length($t);
105
106 print "-----------$r---------\n" if $debug;;
107
108 return $r;
109}
110
111sub fill
112{
113 my ($ip, $xp, @raw) = @_;
114 my @para;
115 my $pp;
116
117 for $pp (split(/\n\s+/, join("\n",@raw))) {
118 $pp =~ s/\s+/ /g;
119 my $x = wrap($ip, $xp, $pp);
120 push(@para, $x);
121 }
122
123 # if paragraph_indent is the same as line_indent,
124 # separate paragraphs with blank lines
125
126 my $ps = ($ip eq $xp) ? "\n\n" : "\n";
127 return join ($ps, @para);
128}
129
13014µs1;
131__END__
 
# spent 2µs within Text::Wrap::CORE:qr which was called: # once (2µs+0s) by Pod::Spell::BEGIN@12 at line 29
sub Text::Wrap::CORE:qr; # opcode