File Coverage

blib/lib/Text/Safer/alphanum_kebab.pm
Criterion Covered Total %
statement 8 12 66.6
branch 0 2 0.0
condition 0 2 0.0
subroutine 3 4 75.0
pod 1 1 100.0
total 12 21 57.1


line stmt bran cond sub pod time code
1             package Text::Safer::alphanum_kebab;
2              
3 1     1   318779 use 5.010001;
  1         3  
4 1     1   5 use strict;
  1         1  
  1         21  
5 1     1   3 use warnings;
  1         1  
  1         240  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2025-06-14'; # DATE
9             our $DIST = 'Text-Safer'; # DIST
10             our $VERSION = '0.003'; # VERSION
11              
12             our %META = (
13             summary => 'Replace sequences of non-alphanumeric characters (underscores not included) with a single dash, e.g. Foo_Bar!!!Baz. -> Foo_Bar-Baz-',
14             args => {
15             lc => {
16             schema => 'bool*',
17             },
18             },
19             );
20              
21             sub encode_safer {
22 0     0 1   my ($text, $args) = @_;
23 0   0       $args //= {};
24              
25 0           $text =~ s/[^A-Za-z0-9_-]+/-/g;
26 0 0         $args->{lc} ? lc($text) : $text;
27             }
28              
29             1;
30             # ABSTRACT: Replace sequences of non-alphanumeric characters (underscores not included) with a single dash, e.g. Foo_Bar!!!Baz. -> Foo_Bar-Baz-
31              
32             __END__