diff options
Diffstat (limited to 'lib/Web/Request/Types.pm')
-rw-r--r-- | lib/Web/Request/Types.pm | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/Web/Request/Types.pm b/lib/Web/Request/Types.pm new file mode 100644 index 0000000..14c99e3 --- /dev/null +++ b/lib/Web/Request/Types.pm @@ -0,0 +1,38 @@ +package Web::Request::Types; +use strict; +use warnings; + +use Moose::Util::TypeConstraints; + +class_type('HTTP::Headers'); + +subtype 'Web::Request::Types::StringLike', + as 'Object', + where { + return unless overload::Method($_, '""'); + my $tc = find_type_constraint('Web::Request::Types::PSGIBodyObject'); + return !$tc->check($_); + }; + +duck_type 'Web::Request::Types::PSGIBodyObject' => ['getline', 'close']; + +subtype 'Web::Request::Types::PSGIBody', + as 'ArrayRef[Str]|FileHandle|Web::Request::Types::PSGIBodyObject'; + +subtype 'Web::Request::Types::HTTPStatus', + as 'Int', + where { /^[1-5][0-9][0-9]$/ }; + +subtype 'Web::Request::Types::HTTP::Headers', + as 'HTTP::Headers'; +coerce 'Web::Request::Types::HTTP::Headers', + from 'ArrayRef', + via { HTTP::Headers->new(@$_) }, + from 'HashRef', + via { HTTP::Headers->new(%$_) }; + +coerce 'Web::Request::Types::PSGIBody', + from 'Str|Web::Request::Types::StringLike', + via { [ $_ ] }; + +1; |