| 1 | package Text::Slugify; | ||||||||||
| 2 | # ABSTRACT: create URL slugs from text | ||||||||||
| 3 | 2 | $Text::Slugify::VERSION = '0.002'; | |||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | our $unaccent = 0; | |||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | if(eval "require Text::Unaccent::PurePerl") { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | 2 | $unaccent = 1; | |||||||||
| 12 | } | ||||||||||
| 13 | 2 | our @EXPORT_OK = qw(slugify); | |||||||||
| 14 | |||||||||||
| 15 | 36 | ▶ | sub slugify { | ||||||||
|
Subroutine
slugify: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 16 | 36 | my ($text) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 36 | ▶ | if($unaccent) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 36 | $text = Text::Unaccent::PurePerl::unac_string($text); | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 36 | $text =~ s/[^a-z0-9]+/-/gi; | |||||||||
| 23 | 36 | $text =~ s/^-?(.+?)-?$/$1/; | |||||||||
| 24 | 36 | $text =~ s/^(.+)$/\L$1/; | |||||||||
| 25 | 36 | return $text; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 2 | 1; | |||||||||
| 29 | |||||||||||
| 30 | __END__ | ||||||||||