Skip to content

Instantly share code, notes, and snippets.

@deppp
Created November 4, 2009 12:32
Show Gist options
  • Save deppp/226007 to your computer and use it in GitHub Desktop.
Save deppp/226007 to your computer and use it in GitHub Desktop.
package App::TypesLibrary;
use URI;
use MooseX::Types -declare => [qw/
Uri
/];
# imports moose types
use MooseX::Types::Moose qw/Str Object/;
# note that syntax differs from the one when
# using Moose::Util::TypeConstraints
subtype Uri,
as Object;
coerce Uri,
from Str,
via { URI->new($_) };
package App::Fetch;
use Moose;
use TypesLibrary 'Uri';
use Data::Dump 'dump';
sub fetch {
my ($self, $url) = @_;
if (! is_Uri($url)) {
$url = to_Uri($url)
}
# no we have URI class instance in $url
dump $url;
}
package main;
my $app = App::Fetch->new;
$app->fetch('www.google.com');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment