Created
November 4, 2009 12:32
-
-
Save deppp/226007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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