shrl.be/lib/Shrlbe/Utils.pm
2023-06-18 09:58:55 +03:00

50 lines
631 B
Perl

package Shrlbe::Utils;
use strict;
use warnings;
use Digest::Adler32;
use URI;
sub new
{
my $class = shift;
my (%params) = @_;
my $self = {%params};
bless $self, $class;
return $self;
}
sub hashUrl
{
my $self = shift;
my ($url) = @_;
my $digest = $self->_buildDigest();
$digest->add($url);
return $digest->hexdigest();
}
sub normalizeUrl
{
my ($self) = shift;
my ($url) = @_;
my $uri = URI->new($url);
$uri = URI->new(sprintf('http://%s', $url )) unless $uri->scheme();
return $uri->as_string;
}
sub _buildDigest
{
return Digest::Adler32->new();
}
1;