blib/lib/Text/HumanComputerWords.pm

filter: Statementstmt 100% 54 / 54 Branchbran 96.4% 27 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 98.9% 96 / 97 CC 17 SCAR 16.5
CC
17
Cov
99%
split
9.0
new
7.0
__ANON__
2.0
CRAP 5.2
↑ Summary
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
BranchTrueFalseTotal
if @args % 2 1 9 10
17  
18 9 my $i=0;
19 9 ▶ while(exists $args[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args[$i]) 18 5 23
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
BranchTrueFalseTotal
unless defined $name 1 17 18
25 17 ▶ croak "argument @{[ $i+2 ]} is undef" unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 1 16 17
26 16 ▶ croak "argument @{[ $i+1 ]} is not a plain string" if is_ref $name;
Branch: 1 branch
BranchTrueFalseTotal
if is_ref($name) 1 15 16
27 15 ▶ croak "argument @{[ $i+2 ]} is not a plain code reference" unless is_plain_coderef $code;
Branch: 1 branch
BranchTrueFalseTotal
unless is_plain_coderef($code) 1 14 15
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
BranchTrueFalseTotal
$text =~ m[^/(bin|boot|dev|etc|home|lib|lib32|lib64|mnt|opt|proc|root|sbin|tmp|usr|var)(/|$)]u or $text =~ m[^[a-z]:[\\/]]iu 2 9 11
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
BranchTrueFalseTotal
$text =~ m[^[a-z]+://]iu or $text =~ /^(file|ftps?|gopher|https?|ldapi|ldaps|mailto|mms|news|nntp|nntps|pop|rlogin|rtsp|sftp|snew|ssh|telnet|tn3270|urn|wss?):\S/iu 1 6 7
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
BranchTrueFalseTotal
unless $frag =~ /\w/u 0 23 23
61  
62 23 my $i=0;
63 23 ▶ while(defined $self->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[$i]) 40 10 50
64 {
65 40 my $name = $self->[$i++];
66 40 my $code = $self->[$i++];
67 40 ▶ if($name eq 'substitute')
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'substitute') { } 2 38 40
elsif (&$code($frag)) { } 13 25 38
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
BranchTrueFalseTotal
unless $name eq "skip" 12 1 13
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
BranchTrueFalseTotal
unless $word =~ /\w/u 5 14 19
82 14 push @result, [ word => $word ];
83 }
84  
85 }
86  
87 5 @result;
88 }
89  
90 1 1;
91  
92 __END__
↑ Summary