| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/5.18.2/Text/Wrap.pm |
| Statements | Executed 28 statements in 948µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 554µs | 687µs | Text::Wrap::BEGIN@35 |
| 1 | 1 | 1 | 15µs | 111µs | Text::Wrap::BEGIN@3 |
| 1 | 1 | 1 | 13µs | 13µs | Text::Wrap::BEGIN@13 |
| 1 | 1 | 1 | 10µs | 26µs | Text::Wrap::BEGIN@58 |
| 1 | 1 | 1 | 9µs | 114µs | Text::Wrap::BEGIN@15 |
| 1 | 1 | 1 | 8µs | 23µs | Text::Wrap::BEGIN@16 |
| 1 | 1 | 1 | 4µs | 4µs | Text::Wrap::BEGIN@18 |
| 1 | 1 | 1 | 2µs | 2µs | Text::Wrap::CORE:qr (opcode) |
| 0 | 0 | 0 | 0s | 0s | Text::Wrap::_xlen |
| 0 | 0 | 0 | 0s | 0s | Text::Wrap::_xpos |
| 0 | 0 | 0 | 0s | 0s | Text::Wrap::fill |
| 0 | 0 | 0 | 0s | 0s | Text::Wrap::wrap |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Text::Wrap; | ||||
| 2 | |||||
| 3 | 2 | 63µs | 2 | 206µ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 # spent 111µs making 1 call to Text::Wrap::BEGIN@3
# spent 95µs making 1 call to warnings::register::import |
| 4 | 1 | 300ns | require Exporter; | ||
| 5 | |||||
| 6 | 1 | 5µs | @ISA = qw(Exporter); | ||
| 7 | 1 | 700ns | @EXPORT = qw(wrap fill); | ||
| 8 | 1 | 500ns | @EXPORT_OK = qw($columns $break $huge); | ||
| 9 | |||||
| 10 | 1 | 200ns | $VERSION = 2012.0818; | ||
| 11 | 1 | 200ns | $SUBVERSION = 'modern'; | ||
| 12 | |||||
| 13 | 2 | 44µs | 1 | 13µs | # spent 13µs within Text::Wrap::BEGIN@13 which was called:
# once (13µs+0s) by Pod::Spell::BEGIN@12 at line 13 # spent 13µs making 1 call to Text::Wrap::BEGIN@13 |
| 14 | |||||
| 15 | 2 | 24µs | 2 | 219µ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 # spent 114µs making 1 call to Text::Wrap::BEGIN@15
# spent 105µs making 1 call to vars::import |
| 16 | 2 | 53µs | 2 | 39µ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 # 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 | ||||
| 19 | 1 | 200ns | $columns = 76; # <= screen width | ||
| 20 | 1 | 0s | $debug = 0; | ||
| 21 | 1 | 200ns | $break = '(?=\s)\X'; | ||
| 22 | 1 | 100ns | $huge = 'wrap'; # alternatively: 'die' or 'overflow' | ||
| 23 | 1 | 0s | $unexpand = 1; | ||
| 24 | 1 | 0s | $tabstop = 8; | ||
| 25 | 1 | 100ns | $separator = "\n"; | ||
| 26 | 1 | 4µs | $separator2 = undef; | ||
| 27 | 1 | 122µs | 1 | 4µs | } # spent 4µs making 1 call to Text::Wrap::BEGIN@18 |
| 28 | |||||
| 29 | 1 | 8µs | 1 | 2µs | my $CHUNK = qr/\X/; # spent 2µs making 1 call to Text::Wrap::CORE:qr |
| 30 | |||||
| 31 | sub _xlen(_) { scalar(() = $_[0] =~ /$CHUNK/g) } | ||||
| 32 | |||||
| 33 | sub _xpos(_) { _xlen( substr( $_[0], 0, pos($_[0]) ) ) } | ||||
| 34 | |||||
| 35 | 2 | 262µs | 2 | 733µ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 # spent 687µs making 1 call to Text::Wrap::BEGIN@35
# spent 45µs making 1 call to Exporter::import |
| 36 | |||||
| 37 | sub 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 | |||||
| 58 | 2 | 356µs | 2 | 41µ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 # 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 | |||||
| 111 | sub 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 | |||||
| 130 | 1 | 4µs | 1; | ||
| 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 |