File Coverage

blib/lib/Data/Sah/Filter/perl/Array/dupestr.pm
Criterion Covered Total %
statement 8 17 47.0
branch 0 2 0.0
condition 0 2 0.0
subroutine 3 5 60.0
pod 0 2 0.0
total 11 28 39.2


line stmt bran cond sub pod time code
1             package Data::Sah::Filter::perl::Array::dupestr;
2              
3 1     1   325095 use 5.010001;
  1         4  
4 1     1   8 use strict;
  1         2  
  1         30  
5 1     1   11 use warnings;
  1         2  
  1         410  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2024-02-06'; # DATE
9             our $DIST = 'Data-Sah-FilterBundle-Array'; # DIST
10             our $VERSION = '0.002'; # VERSION
11              
12             sub meta {
13             +{
14 0     0 0   v => 1,
15             summary => 'Return the elements of array that appear more than once',
16             args => {
17             uniq => {
18             summary => 'If set to true, will only list each duplicate once',
19             schema => 'bool*',
20             },
21             },
22             examples => [
23             {value=>[], filtered_value=>[]},
24             {value=>["a","b"], filtered_value=>[]},
25             {value=>["a","b","a","a","c","b"], filtered_value=>["a","a","b"]},
26             {value=>["a","b","a","a","c","b"], filter_args=>{uniq=>1}, filtered_value=>["a","b"]},
27             ],
28             };
29             }
30              
31             sub filter {
32 0     0 0   my %fargs = @_;
33              
34 0           my $dt = $fargs{data_term};
35 0   0       my $gen_args = $fargs{args} // {};
36              
37 0           my $res = {};
38 0           $res->{modules}{'List::Util'} = 1.54;
39 0           $res->{modules}{'List::Util::Uniq'} = 1.54;
40             $res->{expr_filter} = join(
41             "",
42 0 0         ($gen_args->{uniq} ? "[List::Util::uniqstr(List::Util::Uniq::dupestr(\@{ $dt }))]" : "[List::Util::Uniq::dupestr(\@{ $dt })]"),
43             );
44              
45 0           $res;
46             }
47              
48             1;
49             # ABSTRACT: Return the elements of array that appear more than once
50              
51             __END__