| 1 | package Text::HumanComputerWords; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use 5.022; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use experimental qw( signatures refaliasing ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use Ref::Util qw( is_ref is_plain_coderef ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use Carp qw( croak ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | # ABSTRACT: Split human and computer words in a naturalish manner | ||||||||||||||
| 11 | 1 | our $VERSION = '0.04'; # VERSION | |||||||||||||
| 12 | |||||||||||||||
| 13 | |||||||||||||||
| 14 | 10 | ▶ | sub new ($class, @args) | ||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||
| 15 | { | ||||||||||||||
| 16 | 10 | ▶ | croak "uneven arguments passed to constructor" if @args % 2; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | 9 | my $i=0; | |||||||||||||
| 19 | 9 | ▶ | while(exists $args[$i]) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | { | ||||||||||||||
| 21 | 18 | my $name = $args[$i]; | |||||||||||||
| 22 | 18 | my $code = $args[$i+1]; | |||||||||||||
| 23 | |||||||||||||||
| 24 | 18 | ▶ | croak "argument @{[ $i+1 ]} is undef" unless defined $name; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | 17 | ▶ | croak "argument @{[ $i+2 ]} is undef" unless defined $code; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | 16 | ▶ | croak "argument @{[ $i+1 ]} is not a plain string" if is_ref $name; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 15 | ▶ | croak "argument @{[ $i+2 ]} is not a plain code reference" unless is_plain_coderef $code; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | |||||||||||||||
| 29 | 14 | $i+=2; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 5 | bless [@args], $class; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | |||||||||||||||
| 36 | sub default_perl | ||||||||||||||
| 37 | 1 | ▶ | { | ||||||||||||
|
Subroutine
default_perl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 38 | return ( | ||||||||||||||
| 39 | 11 | ▶ | path_name => sub ($text) { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 40 | 11 | ▶ | $text =~ m{^/(bin|boot|dev|etc|home|lib|lib32|lib64|mnt|opt|proc|root|sbin|tmp|usr|var)(/|$)} | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | || $text =~ m{^[a-z]:[\\/]}i | ||||||||||||||
| 42 | }, | ||||||||||||||
| 43 | 7 | ▶ | url_link => sub ($text) { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 44 | 7 | ▶ | $text =~ /^[a-z]+:\/\//i | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | || $text =~ /^(file|ftps?|gopher|https?|ldapi|ldaps|mailto|mms|news|nntp|nntps|pop|rlogin|rtsp|sftp|snew|ssh|telnet|tn3270|urn|wss?):\S/i | ||||||||||||||
| 46 | }, | ||||||||||||||
| 47 | 5 | ▶ | module => sub ($text) { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 48 | 5 | $text =~ /^[a-z]+::([a-z]+(::[a-z]+)*('s)?)$/i | |||||||||||||
| 49 | }, | ||||||||||||||
| 50 | 1 | ); | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | |||||||||||||||
| 54 | 5 | ▶ | sub split ($self, $text) | ||||||||||||
|
Subroutine
split: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||
| 55 | { | ||||||||||||||
| 56 | 5 | my @result; | |||||||||||||
| 57 | |||||||||||||||
| 58 | 5 | frag_loop: foreach my $frag (CORE::split /\s+/, $text) | |||||||||||||
| 59 | { | ||||||||||||||
| 60 | 23 | ▶ | next unless $frag =~ /\w/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | |||||||||||||||
| 62 | 23 | my $i=0; | |||||||||||||
| 63 | 23 | ▶ | while(defined $self->[$i]) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | { | ||||||||||||||
| 65 | 40 | my $name = $self->[$i++]; | |||||||||||||
| 66 | 40 | my $code = $self->[$i++]; | |||||||||||||
| 67 | 40 | ▶ | if($name eq 'substitute') | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 68 | { | ||||||||||||||
| 69 | 2 | \local $_ = \$frag; | |||||||||||||
| 70 | 2 | $code->(); | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | elsif($code->($frag)) | ||||||||||||||
| 73 | { | ||||||||||||||
| 74 | 13 | ▶ | push @result, [ $name, $frag ] unless $name eq 'skip'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | 13 | next frag_loop; | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 10 | word_loop: foreach my $word (CORE::split /\b{wb}/, $frag) | |||||||||||||
| 80 | { | ||||||||||||||
| 81 | 19 | ▶ | next word_loop unless $word =~ /\w/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 82 | 14 | push @result, [ word => $word ]; | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | } | ||||||||||||||
| 86 | |||||||||||||||
| 87 | 5 | @result; | |||||||||||||
| 88 | } | ||||||||||||||
| 89 | |||||||||||||||
| 90 | 1 | 1; | |||||||||||||
| 91 | |||||||||||||||
| 92 | __END__ | ||||||||||||||