Skip to content

Commit

Permalink
Slug role
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Apr 19, 2019
1 parent 28e2578 commit a3dfe1c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Literature/lib/Literature/Role/HasSlug.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Literature::Role::HasSlug;

use Moose::Role;

requires qw[slug slug_cols];

sub make_slug {
my $self = shift;

my $slug = lc join '_', map { $self->$_ } $self->slug_cols;

$slug =~ s/\s+/-/g;
$slug =~ s/[^-\w]+//g;

return $slug;
}

1;

0 comments on commit a3dfe1c

Please sign in to comment.