50 lines
631 B
Perl
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;
|