File Coverage

blib/lib/Text/Format.pm
Criterion Covered Total %
statement 162 281 57.6
branch 104 276 37.6
condition 45 111 40.5
subroutine 12 29 41.3
pod 23 23 100.0
total 346 720 48.0


line stmt bran cond sub pod time code
1             package Text::Format;
2             $Text::Format::VERSION = '0.63';
3             require 5.006;
4              
5              
6 3     3   428666 use strict;
  3         4  
  3         104  
7 3     3   22 use warnings;
  3         4  
  3         163  
8              
9 3     3   18 use Carp;
  3         6  
  3         13508  
10              
11             # local abbreviations, you can add your own with abbrevs()
12             my %abbrev = (
13             Mr => 1,
14             Mrs => 1,
15             Ms => 1,
16             Jr => 1,
17             Sr => 1,
18             );
19              
20             # formats text into a nice paragraph format. can set a variety of
21             # attributes such as first line indent, body indent, left and right
22             # margin, right align, right fill with spaces, non-breaking spaces,
23             # justification to both margins
24             sub format($@)
25             {
26 13     13 1 1679 my $this = shift;
27 13 50       37 croak "Bad method call"
28             unless ref $this;
29 13 50       54 my @wrap = @_
30             if @_ > 0;
31              
32 13 50       33 @wrap = @{ $_[0] }
  0         0  
33             if ref $_[0] eq 'ARRAY';
34 13 50       33 @wrap = @{ $this->{'_text'} }
  0         0  
35             if @wrap < 1;
36              
37 13         40 my $findent = ' ' x $this->{'_findent'};
38 13         29 my $bindent = ' ' x $this->{'_bindent'};
39              
40 13         114 my @words = split /\s+/, join ' ', @wrap;
41             shift @words
42 13 50 33     71 unless defined( $words[0] ) && $words[0] ne '';
43              
44             #if $words[0] eq '';
45              
46 13         27 @wrap = ();
47 13         25 my ( $line, $width, $abbrev );
48 13         20 $abbrev = 0;
49             $width =
50             $this->{'_cols'} -
51             $this->{'_findent'} -
52             $this->{'_lmargin'} -
53 13         37 $this->{'_rmargin'};
54 13         28 $line = shift @words;
55 13 50       52 $abbrev = $this->__is_abbrev($line)
56             if defined $line;
57 13         23 my $nextword;
58              
59 13         39 while ( defined( $nextword = shift @words ) )
60             {
61              
62 46 100 33     175 if ( length($nextword) + length($line) < $width - 1
      33        
      66        
63             || ( $line !~ /[.?!]['"]?$/ || $abbrev )
64             && length($nextword) + length($line) < $width )
65             {
66 38 50 33     123 $line .= ' '
67             if $line =~ /[.?!]['"]?$/ && !$abbrev;
68 38         73 $line .= ' ' . $nextword;
69             }
70             else
71             {
72 8         20 last;
73             }
74 38         75 $abbrev = $this->__is_abbrev($nextword);
75             }
76             ( $line, $nextword ) = $this->__do_break( $line, $nextword )
77 13 50 33     38 if $this->{'_nobreak'} && defined $line;
78 13 50       68 push @wrap,
79             $this->__make_line( $line, $findent, $width, defined($nextword) )
80             if defined $line;
81 13         28 $line = $nextword;
82             $width =
83             $this->{'_cols'} -
84             $this->{'_bindent'} -
85             $this->{'_lmargin'} -
86 13         31 $this->{'_rmargin'};
87 13         24 $abbrev = 0;
88 13 100       72 $abbrev = $this->__is_abbrev($line)
89             if defined $line;
90 13         41 while ( defined( $nextword = shift @words ) )
91             {
92              
93 256 100 33     943 if ( length($nextword) + length($line) < $width - 1
      66        
      100        
94             || ( $line !~ /[.?!]['"]?$/ || $abbrev )
95             && length($nextword) + length($line) < $width )
96             {
97 208 100 100     610 $line .= ' '
98             if $line =~ /[.?!]['"]?$/ && !$abbrev;
99 208         350 $line .= ' ' . $nextword;
100             }
101             else
102             {
103             ( $line, $nextword ) = $this->__do_break( $line, $nextword )
104 48 50       122 if $this->{'_nobreak'};
105 48 50       153 push @wrap,
106             $this->__make_line( $line, $bindent, $width, defined $nextword )
107             if defined $line;
108 48         96 $line = $nextword;
109             }
110 256 50       681 $abbrev = $this->__is_abbrev($nextword)
111             if defined $nextword;
112             }
113 13 100       42 push @wrap, $this->__make_line( $line, $bindent, $width, 0 )
114             if defined $line;
115              
116 13 50 33     38 if ( $this->{'_hindent'} && @wrap > 0 )
117             {
118 0         0 my $caller = ( caller 1 )[3];
119 0 0       0 $caller = ''
120             unless defined $caller;
121             $this->{'_hindcurr'} = $this->{'_hindtext'}->[0]
122             if defined $this->{'_hindtext'}->[0]
123 0 0 0     0 && length( $this->{'_hindcurr'} ) < 1
      0        
124             && $caller ne 'Text::Format::paragraphs';
125 0         0 my ($fchar) = $wrap[0] =~ /(\S)/;
126 0         0 my $white = index $wrap[0], $fchar;
127 0 0       0 if ( $white - $this->{'_lmargin'} - 1 > length( $this->{'_hindcurr'} ) )
128             {
129 0         0 $white = length( $this->{'_hindcurr'} ) + $this->{'_lmargin'};
130 0         0 $wrap[0] =~
131 0         0 s/^ {$white}/' ' x $this->{'_lmargin'} . $this->{'_hindcurr'}/e;
132             }
133             else
134             {
135             unshift @wrap,
136 0         0 ' ' x $this->{'_lmargin'} . $this->{'_hindcurr'} . "\n";
137             }
138             }
139              
140             wantarray
141             ? @wrap
142 13 100       151 : join '', @wrap;
143             }
144              
145             # format lines in text into paragraphs with each element of @wrap a
146             # paragraph; uses Text::Format->format for the formatting
147             sub paragraphs($@)
148             {
149 1     1 1 6 my $this = shift;
150 1 50       4 croak "Bad method call"
151             unless ref $this;
152 1 50       6 my @wrap = @_
153             if @_ > 0;
154              
155 1 50       3 @wrap = @{ $_[0] }
  0         0  
156             if ref $_[0] eq 'ARRAY';
157 1 50       7 @wrap = @{ $this->{'_text'} }
  0         0  
158             if @wrap < 1;
159              
160 1         3 my ( @ret, $end, $cnt, $line );
161              
162             # if indents are same, use newline between paragraphs
163 1 50 33     11 if ( $this->{'_findent'} == $this->{'_bindent'}
164             || $this->{'_hindent'} )
165             {
166 0         0 $end = "\n";
167             }
168             else
169             {
170 1         3 $end = '';
171             }
172              
173 1         2 $cnt = 0;
174 1         4 for my $nextword (@wrap)
175             {
176             $this->{'_hindcurr'} = $this->{'_hindtext'}->[$cnt]
177 2 50       6 if $this->{'_hindent'};
178             $this->{'_hindcurr'} = ''
179 2 50       13 unless defined $this->{'_hindcurr'};
180 2         7 $line = $this->format($nextword);
181 2 50 33     13 push @ret, $line . $end
182             if defined $line && length $line > 0;
183 2         5 ++$cnt;
184             }
185 1 50 33     9 chop $ret[$#ret]
186             if defined( $ret[$#ret] ) && $ret[$#ret] =~ /\n\n$/;
187              
188             #if $ret[$#ret] =~ /\n\n$/;
189              
190             wantarray
191             ? @ret
192 1 50       7 : join '', @ret;
193             }
194              
195             # center text using spaces on left side to pad it out
196             # empty lines are preserved
197             sub center($@)
198             {
199 1     1 1 1024 my $this = shift;
200 1 50       6 croak "Bad method call"
201             unless ref $this;
202 1 50       6 my @center = @_
203             if @_ > 0;
204 1 50       4 @center = @{ $this->{'_text'} }
  0         0  
205             if @center < 1;
206 1         2 my ($tabs);
207 1         4 my $width = $this->{'_cols'} - $this->{'_lmargin'} - $this->{'_rmargin'};
208              
209 1         3 for my $nextword (@center)
210             {
211 2         15 $nextword =~ s/(?:^\s+|\s+$)|\n//g;
212 2         6 $tabs = ( $nextword =~ tr/\t// ); # count tabs
213             substr( $nextword, 0, 0 ) =
214             ' ' x
215             int(
216 2 50       17 ( $width - length($nextword) - $tabs * $this->{'_tabs'} + $tabs ) /
217             2 )
218             if length($nextword) > 0;
219 2 50       10 substr( $nextword, 0, 0 ) = ' ' x $this->{'_lmargin'}
220             if length($nextword) > 0;
221 2         6 substr( $nextword, length($nextword) ) = "\n";
222             }
223              
224             return wantarray
225             ? @center
226 1 50       7 : join '', @center;
227             }
228              
229             # expand tabs to spaces
230             # should be similar to Text::Tabs::expand
231             sub expand($@)
232             {
233 0     0 1 0 my $this = shift;
234 0 0       0 croak "Bad method call"
235             unless ref $this;
236 0 0       0 my @lines = @_
237             if @_ > 0;
238 0 0       0 @lines = @{ $this->{'_text'} }
  0         0  
239             if @lines < 1;
240              
241 0         0 for (@lines)
242             {
243 0         0 s/\t/' ' x $this->{'_tabs'}/eg;
  0         0  
244             }
245              
246             wantarray
247             ? @lines
248 0 0       0 : $lines[0];
249             }
250              
251             # turn tabstop number of spaces into tabs
252             # should be similar to Text::Tabs::unexpand
253             sub unexpand($@)
254             {
255 0     0 1 0 my $this = shift;
256 0 0       0 croak "Bad method call"
257             unless ref $this;
258 0         0 my @lines = $this->expand(@_);
259              
260 0         0 for (@lines)
261             {
262 0         0 s/ {$this->{'_tabs'}}/\t/g;
263             }
264              
265             wantarray
266             ? @lines
267 0 0       0 : $lines[0];
268             }
269              
270             # return a reference to the object, call as $text = Text::Format->new()
271             # can be used to clone the current reference $ntext = $text->new()
272             sub new($@)
273             {
274 3     3 1 644224 my $this = shift;
275 3         7 my $ref;
276 3 100       21 if ( ref $_[0] eq 'HASH' )
    50          
277             {
278 1         4 $ref = shift;
279             }
280             elsif ( scalar(@_) % 2 == 0 )
281             {
282 2         5 my %ref = @_;
283 2         6 $ref = \%ref;
284             }
285             else
286             {
287 0         0 $ref = '';
288             }
289 3 50       13 my %clone = %{$this}
  0         0  
290             if ref $this;
291              
292 3         43 my $conf = {
293             _cols => 72,
294             _tabs => 8,
295             _findent => 4,
296             _bindent => 0,
297             _fill => 0,
298             _align => 0,
299             _justify => 0,
300             _lmargin => 0,
301             _rmargin => 0,
302             _space => 0,
303             _abbrs => {},
304             _text => [],
305             _hindent => 0,
306             _hindtext => [],
307             _hindcurr => '',
308             _nobreak => 0,
309             _nobreakregex => {},
310             };
311              
312 3 50       14 if ( ref $ref eq 'HASH' )
313             {
314             $conf->{'_cols'} = abs int $ref->{'columns'}
315 3 100       18 if defined $ref->{'columns'};
316             $conf->{'_tabs'} = abs int $ref->{'tabstop'}
317 3 50       16 if defined $ref->{'tabstop'};
318             $conf->{'_findent'} = abs int $ref->{'firstIndent'}
319 3 100       13 if defined $ref->{'firstIndent'};
320             $conf->{'_bindent'} = abs int $ref->{'bodyIndent'}
321 3 50       11 if defined $ref->{'bodyIndent'};
322             $conf->{'_fill'} = abs int $ref->{'rightFill'}
323 3 50       12 if defined $ref->{'rightFill'};
324             $conf->{'_align'} = abs int $ref->{'rightAlign'}
325 3 50       10 if defined $ref->{'rightAlign'};
326             $conf->{'_justify'} = abs int $ref->{'justify'}
327 3 50       13 if defined $ref->{'justify'};
328             $conf->{'_lmargin'} = abs int $ref->{'leftMargin'}
329 3 50       10 if defined $ref->{'leftMargin'};
330             $conf->{'_rmargin'} = abs int $ref->{'rightMargin'}
331 3 50       11 if defined $ref->{'rightMargin'};
332             $conf->{'_space'} = abs int $ref->{'extraSpace'}
333 3 50       9 if defined $ref->{'extraSpace'};
334             $conf->{'_abbrs'} = $ref->{'abbrevs'}
335             if defined $ref->{'abbrevs'}
336 3 50 33     12 && ref $ref->{'abbrevs'} eq 'HASH';
337             $conf->{'_text'} = $ref->{'text'}
338             if defined $ref->{'text'}
339 3 50 33     13 && ref $ref->{'text'} eq 'ARRAY';
340             $conf->{'_hindent'} = abs int $ref->{'hangingIndent'}
341 3 50       9 if defined $ref->{'hangingIndent'};
342             $conf->{'_hindtext'} = $ref->{'hangingText'}
343             if defined $ref->{'hangingText'}
344 3 50 33     12 && ref $ref->{'hangingText'} eq 'ARRAY';
345             $conf->{'_nobreak'} = abs int $ref->{'noBreak'}
346 3 50       11 if defined $ref->{'noBreak'};
347             $conf->{'_nobreakregex'} = $ref->{'noBreakRegex'}
348             if defined $ref->{'noBreakRegex'}
349 3 50 33     14 && ref $ref->{'noBreakRegex'} eq 'HASH';
350             }
351              
352 3 50       18 ref $this
353             ? bless \%clone, ref $this
354             : bless $conf, $this;
355             }
356              
357             # configure all the attributes of the object
358             # returns the old object prior to configuration
359             sub config($@)
360             {
361 7     7 1 3612 my $this = shift;
362 7 50       27 croak "Bad method call"
363             unless ref $this;
364 7         12 my $conf;
365 7 50       48 if ( ref $_[0] eq 'HASH' )
    0          
366             {
367 7         14 $conf = shift;
368             }
369             elsif ( scalar(@_) % 2 == 0 )
370             {
371 0         0 my %conf = @_;
372 0         0 $conf = \%conf;
373             }
374             else
375             {
376 0         0 croak "Bad hash ref";
377             }
378 7         15 my %clone = %{$this};
  7         80  
379              
380             $this->{'_cols'} = abs int $conf->{'columns'}
381 7 100       34 if defined $conf->{'columns'};
382             $this->{'_tabs'} = abs int $conf->{'tabstop'}
383 7 50       20 if defined $conf->{'tabstop'};
384             $this->{'_findent'} = abs int $conf->{'firstIndent'}
385 7 50       16 if defined $conf->{'firstIndent'};
386             $this->{'_bindent'} = abs int $conf->{'bodyIndent'}
387 7 50       18 if defined $conf->{'bodyIndent'};
388             $this->{'_fill'} = abs int $conf->{'rightFill'}
389 7 50       22 if defined $conf->{'rightFill'};
390             $this->{'_align'} = abs int $conf->{'rightAlign'}
391 7 50       15 if defined $conf->{'rightAlign'};
392             $this->{'_justify'} = abs int $conf->{'justify'}
393 7 50       28 if defined $conf->{'justify'};
394             $this->{'_lmargin'} = abs int $conf->{'leftMargin'}
395 7 50       16 if defined $conf->{'leftMargin'};
396             $this->{'_rmargin'} = abs int $conf->{'rightMargin'}
397 7 50       16 if defined $conf->{'rightMargin'};
398             $this->{'_space'} = abs int $conf->{'extraSpace'}
399 7 100       18 if defined $conf->{'extraSpace'};
400             $this->{'_abbrs'} = $conf->{'abbrevs'}
401             if defined $conf->{'abbrevs'}
402 7 50 33     21 && ref $conf->{'abbrevs'} eq 'HASH';
403             $this->{'_text'} = $conf->{'text'}
404             if defined $conf->{'text'}
405 7 50 33     17 && ref $conf->{'text'} eq 'ARRAY';
406             $this->{'_hindent'} = abs int $conf->{'hangingIndent'}
407 7 50       16 if defined $conf->{'hangingIndent'};
408             $this->{'_hindtext'} = $conf->{'hangingText'}
409             if defined $conf->{'hangingText'}
410 7 50 33     21 && ref $conf->{'hangingText'} eq 'ARRAY';
411             $this->{'_nobreak'} = abs int $conf->{'noBreak'}
412 7 50       16 if defined $conf->{'noBreak'};
413             $this->{'_nobreakregex'} = $conf->{'noBreakRegex'}
414             if defined $conf->{'noBreakRegex'}
415 7 50 33     20 && ref $conf->{'noBreakRegex'} eq 'HASH';
416              
417 7         29 bless \%clone, ref $this;
418             }
419              
420             sub columns($;$)
421             {
422 1     1 1 945 my $this = shift;
423 1 50       6 croak "Bad method call"
424             unless ref $this;
425              
426             @_
427             ? $this->{'_cols'} = abs int shift
428 1 50       6 : $this->{'_cols'};
429             }
430              
431             sub tabstop($;$)
432             {
433 0     0 1 0 my $this = shift;
434 0 0       0 croak "Bad method call"
435             unless ref $this;
436              
437             @_
438             ? $this->{'_tabs'} = abs int shift
439 0 0       0 : $this->{'_tabs'};
440             }
441              
442             sub firstIndent($;$)
443             {
444 0     0 1 0 my $this = shift;
445 0 0       0 croak "Bad method call"
446             unless ref $this;
447              
448             @_
449             ? $this->{'_findent'} = abs int shift
450 0 0       0 : $this->{'_findent'};
451             }
452              
453             sub bodyIndent($;$)
454             {
455 1     1 1 7 my $this = shift;
456 1 50       4 croak "Bad method call"
457             unless ref $this;
458              
459             @_
460             ? $this->{'_bindent'} = abs int shift
461 1 50       5 : $this->{'_bindent'};
462             }
463              
464             sub rightFill($;$)
465             {
466 0     0 1 0 my $this = shift;
467 0 0       0 croak "Bad method call"
468             unless ref $this;
469              
470             @_
471             ? $this->{'_fill'} = abs int shift
472 0 0       0 : $this->{'_fill'};
473             }
474              
475             sub rightAlign($;$)
476             {
477 0     0 1 0 my $this = shift;
478 0 0       0 croak "Bad method call"
479             unless ref $this;
480              
481             @_
482             ? $this->{'_align'} = abs int shift
483 0 0       0 : $this->{'_align'};
484             }
485              
486             sub justify($;$)
487             {
488 0     0 1 0 my $this = shift;
489 0 0       0 croak "Bad method call"
490             unless ref $this;
491              
492             @_
493             ? $this->{'_justify'} = abs int shift
494 0 0       0 : $this->{'_justify'};
495             }
496              
497             sub leftMargin($;$)
498             {
499 0     0 1 0 my $this = shift;
500 0 0       0 croak "Bad method call"
501             unless ref $this;
502              
503             @_
504             ? $this->{'_lmargin'} = abs int shift
505 0 0       0 : $this->{'_lmargin'};
506             }
507              
508             sub rightMargin($;$)
509             {
510 0     0 1 0 my $this = shift;
511 0 0       0 croak "Bad method call"
512             unless ref $this;
513              
514             @_
515             ? $this->{'_rmargin'} = abs int shift
516 0 0       0 : $this->{'_rmargin'};
517             }
518              
519             sub extraSpace($;$)
520             {
521 0     0 1 0 my $this = shift;
522 0 0       0 croak "Bad method call"
523             unless ref $this;
524              
525             @_
526             ? $this->{'_space'} = abs int shift
527 0 0       0 : $this->{'_space'};
528             }
529              
530             # takes a reference to your hash or takes a list of abbreviations,
531             # returns the INTERNAL abbreviations
532             sub abbrevs($@)
533             {
534 0     0 1 0 my $this = shift;
535 0 0       0 croak "Bad method call"
536             unless ref $this;
537              
538 0 0       0 if ( ref $_[0] eq 'HASH' )
    0          
539             {
540 0         0 $this->{'_abbrs'} = shift;
541             }
542             elsif ( @_ > 0 )
543             {
544 0         0 my %tmp;
545 0         0 @tmp{@_} = @_;
546 0         0 $this->{'_abbrs'} = \%tmp;
547             }
548              
549             wantarray
550 0 0       0 ? sort keys %abbrev
551             : join ' ', sort keys %abbrev;
552             }
553              
554             sub text($;$)
555             {
556 0     0 1 0 my $this = shift;
557 0 0       0 croak "Bad method call"
558             unless ref $this;
559 0         0 my $text = shift;
560              
561 0 0       0 $this->{'_text'} = $text
562             if ref $text eq 'ARRAY';
563              
564             wantarray
565 0         0 ? @{ $this->{'_text'} }
566 0 0       0 : join ' ', @{ $this->{'_text'} };
  0         0  
567             }
568              
569             sub hangingIndent($;$)
570             {
571 0     0 1 0 my $this = shift;
572 0 0       0 croak "Bad method call"
573             unless ref $this;
574              
575             @_
576             ? $this->{'_hindent'} = abs int shift
577 0 0       0 : $this->{'_hindent'};
578             }
579              
580             sub hangingText($;$)
581             {
582 0     0 1 0 my $this = shift;
583 0 0       0 croak "Bad method call"
584             unless ref $this;
585 0         0 my $text = shift;
586              
587 0 0       0 $this->{'_hindtext'} = $text
588             if ref $text eq 'ARRAY';
589              
590             wantarray
591 0         0 ? @{ $this->{'_hindtext'} }
592 0 0       0 : join ' ', @{ $this->{'_hindtext'} };
  0         0  
593             }
594              
595             sub noBreak($;$)
596             {
597 0     0 1 0 my $this = shift;
598 0 0       0 croak "Bad method call"
599             unless ref $this;
600              
601             @_
602             ? $this->{'_nobreak'} = abs int shift
603 0 0       0 : $this->{'_nobreak'};
604             }
605              
606             sub noBreakRegex($;$)
607             {
608 0     0 1 0 my $this = shift;
609 0 0       0 croak "Bad method call"
610             unless ref $this;
611 0         0 my $nobreak = shift;
612              
613 0 0       0 $this->{'_nobreakregex'} = $nobreak
614             if ref $nobreak eq 'HASH';
615              
616 0         0 %{ $this->{'_nobreakregex'} };
  0         0  
617             }
618              
619             # internal routine, should not be called by an external routine
620             sub __make_line($$$$$)
621             {
622 69     69   105 my $this = shift;
623 69 50       141 croak "Bad method call"
624             unless ref $this;
625 69         189 my ( $line, $lead_white, $width, $not_last ) = @_;
626 69         128 my $fill = '';
627 69         151 my $lmargin = ' ' x $this->{'_lmargin'};
628              
629             $fill = ' ' x ( $width - length($line) )
630 69 100 66     272 if $this->{'_fill'} && !$this->{'_align'};
631 69 100 33     487 if ( $this->{'_justify'}
      66        
      66        
      66        
      100        
632             && !( $this->{'_fill'} || $this->{'_align'} )
633             && defined $line
634             && $line =~ /\S+\s+\S+/
635             && $not_last )
636             {
637 26         53 my $spaces = $width - length($line);
638 26         177 my @words = split /(\s+)/, $line;
639 26         93 my $ws = int( $spaces / int( @words / 2 ) ); # for filling all gaps
640 26 100       69 $spaces %= int( @words / 2 )
641             if $ws > 0; # if we must fill between every single word
642             WORDS_LOOP:
643 26         79 for my $nextword ( reverse @words )
644             {
645             next WORDS_LOOP
646 248 100       650 if $nextword =~ /^\S/;
647 111         226 substr( $nextword, 0, 0 ) = ' ' x $ws;
648 111 100       233 $spaces || next WORDS_LOOP;
649 33         52 substr( $nextword, 0, 0 ) = ' ';
650 33         54 --$spaces;
651             }
652 26         125 $line = join '', @words;
653             }
654 69 50       245 $line = $lmargin . $lead_white . $line . $fill . "\n"
655             if defined $line;
656             substr( $line, 0, 0 ) =
657             ' ' x ( $this->{'_cols'} - $this->{'_rmargin'} - ( length($line) - 1 ) )
658 69 0 33     182 if $this->{'_align'} && !$this->{'_fill'} && defined $line;
      33        
659              
660 69         216 $line;
661             }
662              
663             # internal routine, should not be called by an external routine
664             sub __is_abbrev($$)
665             {
666 315     315   497 my $this = shift;
667 315 50       622 croak "Bad method call"
668             unless ref $this;
669 315         551 my $word = shift;
670              
671 315 50       771 $word =~ s/\.$//
672             if defined $word; # remove period if there is one
673             # if we have an abbreviation OR no extra space is wanted after
674             # sentence endings
675             return 1
676             if !$this->{'_space'}
677             || exists( $abbrev{$word} )
678 315 50 66     1197 || exists( ${ $this->{'_abbrs'} }{$word} );
  136   33     427  
679              
680 136         435 0;
681             }
682              
683             # internal routine, should not be called by an external routine
684             sub __do_break($$$)
685             {
686 0     0     my $this = shift;
687 0 0         croak "Bad method call"
688             unless ref $this;
689 0           my ( $line, $next_line ) = @_;
690 0           my $no_break = 0;
691 0 0         my @words = split /\s+/, $line
692             if defined $line;
693 0           my $last_word = $words[$#words];
694 0           local $_;
695              
696 0           for ( keys %{ $this->{'_nobreakregex'} } )
  0            
697             {
698 0 0 0       $no_break = 1
699             if $last_word =~ m$_
700 0           && $next_line =~ m${$this->{'_nobreakregex'}}{$_};
701             }
702              
703 0 0 0       if ( $no_break && @words > 1 )
704             {
705 0           my $i;
706 0           for ( $i = $#words ; $i > 0 ; --$i )
707             {
708 0           $no_break = 0;
709 0           for ( keys %{ $this->{'_nobreakregex'} } )
  0            
710             {
711 0 0 0       $no_break = 1
712             if $words[ $i - 1 ] =~ m$_
713 0           && $words[$i] =~ m${$this->{'_nobreakregex'}}{$_};
714             }
715             last
716 0 0         if !$no_break;
717             }
718 0 0         if ( $i > 0 )
719             { # found break point
720 0           $line =~ s/((?:\S+\s+){$i})(.+)/$1/;
721 0           $next_line = $2 . ' ' . $next_line;
722 0           $line =~ s/\s+$//;
723             }
724              
725             # else, no breakpoint found and must break here anyways :<
726             }
727 0           ( $line, $next_line );
728             }
729              
730             1;
731              
732             __END__