package CMTD::Helpers; use strict; use warnings; use utf8; use Mojo::Base 'Mojolicious::Plugin'; sub register { my ($self, $app) = @_; $app->helper(referrer => sub { my ($c) = @_; my $url = $c->req->headers->referrer || $c->req->param('url'); return $url; }); $app->helper(pageid => sub { my ($c, $url) = @_; return unless $url; my $u = Mojo::URL->new($url); my $site = $u->host; my $path = $u->path; $path =~ s{^/+}{}o; $path =~ s{/+$}{}o; $path =~ y{/.}{-}s; $path =~ s<\.[a-z0-9]{2,4}$><>io; my $md5 = md5_sum($path); return {site => $site, pid => $md5, path => $path}; }); } 1;