Type Coercions (cont.)
- Create any relevant subtypes
subtype 'CGI' => as 'Object' => where { $_->isa('CGI') };
- Tell Moose exactly what and how we want it to coerce.
coerce 'WebApp::Request'
=> from 'HashRef'
=> via { WebApp::Request->new(params => $_) }
=> from 'CGI'
=> via {
my $cgi = shift;
my $r = WebApp::Request->new();
$r->param($_ => $cgi->param($_)) for $cgi->param;
$r;
};