File Coverage

blib/lib/Rope/Handles/String.pm
Criterion Covered Total %
statement 59 59 100.0
branch 10 10 100.0
condition 3 6 50.0
subroutine 14 14 100.0
pod 11 12 91.6
total 97 101 96.0


line stmt bran cond sub pod time code
1             package Rope::Handles::String;
2              
3 2     2   155076 use strict;
  2         4  
  2         57  
4 2     2   12 use warnings;
  2         4  
  2         1045  
5              
6             sub new {
7 11     11 0 257049 my ($class, $str) = @_;
8 11         36 bless \$str, __PACKAGE__;
9             }
10              
11             sub increment {
12 20     20 1 9924 my ($self) = @_;
13 20         22 my $str = ${$self};
  20         29  
14 20   66     152 my $num = $str =~ s/(\d+)$// && $1;
15 20         30 $num++;
16 20         34 ${$self} = $str . $num;
  20         25  
17 20         19 return ${$self};
  20         57  
18             }
19              
20             sub decrement {
21 20     20 1 10143 my ($self) = @_;
22 20         21 my $str = ${$self};
  20         26  
23 20   33     185 my $num = $str =~ s/(\d+)$// && $1;
24 20         34 $num--;
25 20 100       37 ${$self} = $str . ($num == 0 ? '' : $num);
  20         32  
26 20         20 return ${$self};
  20         62  
27             }
28              
29 2     2 1 13 sub append { ${$_[0]} = ${$_[0]} . $_[1] }
  2         11  
  2         3  
30            
31 2     2 1 4 sub prepend { ${$_[0]} = $_[1] . ${$_[0]} }
  2         8  
  2         4  
32              
33             sub replace {
34 3 100   3 1 17 if (ref($_[2]) eq 'CODE') {
    100          
35 1         2 ${$_[0]} =~ s/$_[1]/$_[2]->()/e;
  1         15  
  1         3  
36             }
37             elsif ($_[2]) {
38 1         1 ${$_[0]} =~ s/$_[1]/$_[2]/;
  1         17  
39             } else {
40 1         2 ${$_[0]} =~ s/$_[1]/$1/;
  1         96  
41             }
42 3         10 ${$_[0]};
  3         15  
43             }
44              
45              
46 3     3 1 8 sub match { ${$_[0]} =~ /$_[1]/; }
  3         55  
47              
48 1     1 1 4 sub chop { CORE::chop ${$_[0]} }
  1         7  
49            
50 1     1 1 6 sub chomp { CORE::chomp ${$_[0]} }
  1         5  
51            
52 1     1 1 5 sub clear { ${$_[0]} = '' }
  1         4  
53            
54 4     4 1 5 sub length { CORE::length ${$_[0]} }
  4         17  
55            
56             sub substr {
57 3 100   3 1 19 if (@_ >= 4) {
    100          
58 1         2 substr ${$_[0]}, $_[1], $_[2], $_[3];
  1         4  
59             }
60             elsif (@_ == 3) {
61 1         2 substr ${$_[0]}, $_[1], $_[2];
  1         5  
62             }
63             else {
64 1         1 substr ${$_[0]}, $_[1];
  1         7  
65             }
66             }
67              
68             1;
69              
70             __END__