File Coverage

blib/lib/Rope/Handles/String.pm
Criterion Covered Total %
statement 37 59 62.7
branch 4 10 40.0
condition 3 6 50.0
subroutine 8 14 57.1
pod 11 12 91.6
total 63 101 62.3


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