blib/lib/String/Ident.pm

filter: Statementstmt 100% 41 / 41 Branchbran 83.3% 15 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 95.8% 69 / 72 CC 10 SCAR 12.1
CC
10
Cov
95%
cleanup
6.0
min_len
3.0
max_len
3.0
CRAP 3.3
↑ Summary
1 package String::Ident;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = 0.05;
8  
9 1 ▶use Text::Unidecode 'unidecode';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
13 9 my ( $class, %args ) = @_;
14 return bless {
15 min_len => $args{min_len},
16 max_len => $args{max_len},
17 9 }, $class;
18 }
19  
20 18 ▶sub min_len {
Subroutine min_len: called CC=3 SCAR=11.0
Pod documented
21 18 my ( $self, $new ) = @_;
22 18 ▶ $self->{min_len} = $new if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 18 18
23 $self->{min_len} = 4
24 18 ▶ unless defined( $self->{min_len} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"min_len"} 7 11 18
25 18 return $self->{min_len};
26 }
27  
28 8 ▶sub max_len {
Subroutine max_len: called CC=3 SCAR=11.0
Pod documented
29 8 my ( $self, $new ) = @_;
30 8 ▶ $self->{max_len} = $new if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 8 8
31 $self->{max_len} = 30
32 8 ▶ unless defined( $self->{max_len} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"max_len"} 3 5 8
33 8 return $self->{max_len};
34 }
35  
36 12 ▶sub cleanup {
Subroutine cleanup: called CC=6 SCAR=17.9
Pod documented
37 12 my ( $self, $text, $max_len ) = @_;
38  
39 12 ▶ $self = $self->new( max_len => $max_len )
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) 7 5 12
40 unless blessed($self);
41 12 ▶ $max_len = ( defined($max_len) ? $max_len : $self->max_len );
Branch: 1 branch
BranchTrueFalseTotal
defined $max_len ? : 4 8 12
42  
43 12 ▶ $text = '' unless defined($text);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 12 12
44 12 $text = unidecode($text);
45 12 $text =~ s/[^-A-Za-z0-9]/-/g;
46 12 $text =~ s/--+/-/g;
47 12 $text =~ s/-$//g;
48 12 $text =~ s/^-//g;
49  
50 12 ▶ if ( $max_len > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_len > 0) 8 4 12
51 8 $text = substr( $text, 0, $max_len );
52 }
53 12 ▶ while ( length($text) < $self->min_len ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text < $self->min_len) 6 12 18
54 6 $text .= chr( ord('a') + rand( ord('z') - ord('a') + 1 ) );
55 }
56  
57 12 return $text;
58 }
59  
60 1 1;
61  
62 __END__
↑ Summary