File Coverage

lib/Spreadsheet/Engine/Function/SUBSTITUTE.pm
Criterion Covered Total %
statement 20 20 100.0
branch 8 10 80.0
condition n/a
subroutine 6 6 100.0
pod 3 3 100.0
total 37 39 94.8


line stmt bran cond sub pod time code
1             package Spreadsheet::Engine::Function::SUBSTITUTE;
2              
3 28     28   150 use strict;
  28         53  
  28         887  
4 28     28   151 use warnings;
  28         56  
  28         725  
5              
6 28     28   134 use base 'Spreadsheet::Engine::Fn::text';
  28         57  
  28         25761  
7              
8 69     69 1 254 sub argument_count { -3 => 4 }
9 69     69 1 350 sub signature { 't', 't', 't', '!=0' }
10              
11             sub calculate {
12 60     60 1 8460 my ($self, $string, $oldtext, $newtext, $which) = @_;
13              
14 60 100       188 if (!$which) {
    50          
15 47 100       772 $string =~ s/\Q$oldtext\E/$newtext/g if length $oldtext > 0;
16             } elsif ($which >= 1) {
17 13         43 for my $i (1 .. $which) {
18 26 100       58 if ($i == $which) {
19 13         253 $string =~ s/\G(.*?)\Q$oldtext\E/$1$newtext/;
20 13         39 last;
21             }
22 13 50       106 last unless $string =~ m/\Q$oldtext\E/g;
23             }
24             }
25 60         390 return $string;
26             }
27              
28             1;
29              
30             __END__