| 1 | package Text::Info::Utils; | ||||||||||||
| 2 | 6 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 6 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 6 | ▶ | use Lingua::Identify::CLD; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | =head1 NAME | ||||||||||||
| 8 | |||||||||||||
| 9 | Text::Info::Utils - Utility methods for L<Text::Info>. | ||||||||||||
| 10 | |||||||||||||
| 11 | =head1 METHODS | ||||||||||||
| 12 | |||||||||||||
| 13 | =over | ||||||||||||
| 14 | |||||||||||||
| 15 | =item CLD() | ||||||||||||
| 16 | |||||||||||||
| 17 | Returns a C<Lingua::Identify::CLD> instance. | ||||||||||||
| 18 | |||||||||||||
| 19 | =cut | ||||||||||||
| 20 | |||||||||||||
| 21 | 6 | has 'CLD' => ( isa => 'Lingua::Identify::CLD', is => 'ro', lazy_build => 1 ); | |||||||||||
| 22 | |||||||||||||
| 23 | 5 | ▶ | sub _build_CLD { | ||||||||||
|
Subroutine
_build_CLD: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 5 | my $self = shift; | |||||||||||
| 25 | |||||||||||||
| 26 | 5 | return Lingua::Identify::CLD->new; | |||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | =item text2words( $text ) | ||||||||||||
| 30 | |||||||||||||
| 31 | Returns an array reference of the words in the specified C<$text>. | ||||||||||||
| 32 | |||||||||||||
| 33 | =cut | ||||||||||||
| 34 | |||||||||||||
| 35 | 6 | ▶ | sub text2words { | ||||||||||
|
Subroutine
text2words: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||
| 36 | 6 | my $self = shift; | |||||||||||
| 37 | 6 | ▶ | my $text = shift // ''; | ||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 38 | |||||||||||||
| 39 | 6 | my @words = (); | |||||||||||
| 40 | |||||||||||||
| 41 | 6 | foreach my $word ( split(/[\s+-]/, $text) ) { | |||||||||||
| 42 | 58 | $word =~ s/^\W+//; | |||||||||||
| 43 | 58 | $word =~ s/\W+$//; | |||||||||||
| 44 | 58 | $word = $self->trim( $word ); | |||||||||||
| 45 | |||||||||||||
| 46 | 58 | ▶ | if ( length $word ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 58 | push( @words, $word ); | |||||||||||
| 48 | } | ||||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | 6 | return \@words; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | =item trim( $text ) | ||||||||||||
| 55 | |||||||||||||
| 56 | Removes leading and trailing spaces from C<$text>. | ||||||||||||
| 57 | |||||||||||||
| 58 | =cut | ||||||||||||
| 59 | |||||||||||||
| 60 | 106 | ▶ | sub trim { | ||||||||||
|
Subroutine
trim: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 61 | 106 | my $self = shift; | |||||||||||
| 62 | 106 | ▶ | my $text = shift // ''; | ||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 63 | |||||||||||||
| 64 | 106 | $text =~ s/^\s+//; | |||||||||||
| 65 | 106 | $text =~ s/\s+$//; | |||||||||||
| 66 | |||||||||||||
| 67 | 106 | return $text; | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | =item squish( $text ) | ||||||||||||
| 71 | |||||||||||||
| 72 | Squishes the C<$text>, ie. replaces all double spaces with one space. | ||||||||||||
| 73 | |||||||||||||
| 74 | =cut | ||||||||||||
| 75 | |||||||||||||
| 76 | 48 | ▶ | sub squish { | ||||||||||
|
Subroutine
squish: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 77 | 48 | my $self = shift; | |||||||||||
| 78 | 48 | ▶ | my $text = shift // ''; | ||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 79 | |||||||||||||
| 80 | 48 | $text =~ s/\s+/ /sg; | |||||||||||
| 81 | |||||||||||||
| 82 | 48 | foreach my $sep ( (".", ",", "!", "?", ":", ";", "ยด", "`", "'") ) { | |||||||||||
| 83 | 432 | $text =~ s/\s+\Q$sep\E\s+/, /sg; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 48 | return $self->trim( $text ); | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 6 | 1; | |||||||||||
| 90 | |||||||||||||
| 91 | =back | ||||||||||||