| 1 | package Magpie::Types; | ||||||||||||||
| 2 | 49 | $Magpie::Types::VERSION = '1.141660'; | |||||||||||||
| 3 | # ABSTRACT: Common Magpie Type Constraints | ||||||||||||||
| 4 | 49 | ▶ | use Moose::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | #use HTTP::Throwable::Factory; | ||||||||||||||
| 6 | 49 | ▶ | use Magpie::Error; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 49 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 49 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 49 | ▶ | use Class::Load; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 49 | my %http_lookup = ( | |||||||||||||
| 12 | 300 => 'MultipleChoices', | ||||||||||||||
| 13 | 301 => 'MovedPermanently', | ||||||||||||||
| 14 | 302 => 'Found', | ||||||||||||||
| 15 | 303 => 'SeeOther', | ||||||||||||||
| 16 | 304 => 'NotModified', | ||||||||||||||
| 17 | 305 => 'UseProxy', | ||||||||||||||
| 18 | 307 => 'TemporaryRedirect', | ||||||||||||||
| 19 | 400 => 'BadRequest', | ||||||||||||||
| 20 | 401 => 'Unauthorized', | ||||||||||||||
| 21 | 403 => 'Forbidden', | ||||||||||||||
| 22 | 404 => 'NotFound', | ||||||||||||||
| 23 | 405 => 'MethodNotAllowed', | ||||||||||||||
| 24 | 406 => 'NotAcceptable', | ||||||||||||||
| 25 | 407 => 'ProxyAuthenticationRequired', | ||||||||||||||
| 26 | 408 => 'RequestTimeout', | ||||||||||||||
| 27 | 409 => 'Conflict', | ||||||||||||||
| 28 | 410 => 'Gone', | ||||||||||||||
| 29 | 411 => 'LengthRequired', | ||||||||||||||
| 30 | 412 => 'PreconditionFailed', | ||||||||||||||
| 31 | 413 => 'RequestEntityTooLarge', | ||||||||||||||
| 32 | 414 => 'RequestURITooLong', | ||||||||||||||
| 33 | 415 => 'UnsupportedMediaType', | ||||||||||||||
| 34 | 416 => 'RequestedRangeNotSatisfiable', | ||||||||||||||
| 35 | 417 => 'ExpectationFailed', | ||||||||||||||
| 36 | 418 => 'ImATeapot', | ||||||||||||||
| 37 | 500 => 'InternalServerError', | ||||||||||||||
| 38 | 501 => 'NotImplemented', | ||||||||||||||
| 39 | 502 => 'BadGateway,', | ||||||||||||||
| 40 | 503 => 'ServiceUnavailable', | ||||||||||||||
| 41 | 504 => 'GatewayTimeout', | ||||||||||||||
| 42 | 505 => 'HTTPVersionNotSupported', | ||||||||||||||
| 43 | ); | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 49 | subtype 'SmartHTTPError' => as 'Maybe[Object]'; | |||||||||||||
| 46 | |||||||||||||||
| 47 | coerce 'SmartHTTPError' | ||||||||||||||
| 48 | => from 'HashRef' | ||||||||||||||
| 49 | => via { | ||||||||||||||
| 50 | 4 | ▶ | my $hash = $_; | ||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=22.3
| |||||||||||||||
| 51 | 4 | ▶ | if (blessed $hash->{reason}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 0 | ▶ | if ($hash->{reason}->isa('Moose::Exception')) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 53 | 0 | $hash->{reason} = "$hash->{reason}"; | |||||||||||||
| 54 | } | ||||||||||||||
| 55 | elsif ($hash->{reason}->can('as_string')) { | ||||||||||||||
| 56 | 0 | $hash->{reason} = $hash->{reason}->as_string; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | else { | ||||||||||||||
| 59 | 0 | warn "Trouble coercing error. Reason expected to be a string but we got '" . $hash->{reason} . "' instead."; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | } | ||||||||||||||
| 63 | 4 | Magpie::Error->new_exception($hash) }, | |||||||||||||
| 64 | => from 'Int' | ||||||||||||||
| 65 | 1 | ▶ | => via { my $name = code_lookup($_); return HTTP::Throwable::Factory->new_exception( $name => {}) }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 66 | => from 'Str' | ||||||||||||||
| 67 | 1 | ▶ | => via { Magpie::Error->new_exception($_ => {}) }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 68 | 49 | ; | |||||||||||||
| 69 | |||||||||||||||
| 70 | sub code_lookup { | ||||||||||||||
| 71 | 1 | ▶ | my $numeric = shift; | ||||||||||||
|
Subroutine
code_lookup: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||
| 72 | 1 | ▶ | return defined( $http_lookup{$numeric} ) ? $http_lookup{$numeric} : $http_lookup{'500'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 49 | subtype 'MagpieResourceObject' => as 'Maybe[Object]'; | |||||||||||||
| 76 | |||||||||||||||
| 77 | coerce 'MagpieResourceObject' | ||||||||||||||
| 78 | => from 'HashRef' | ||||||||||||||
| 79 | => via { | ||||||||||||||
| 80 | 0 | ▶ | my $args = $_; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 81 | 0 | my $class = delete $args->{class}; | |||||||||||||
| 82 | 0 | Class::Load::load_class( $class ); | |||||||||||||
| 83 | 0 | $class->new( $args ); | |||||||||||||
| 84 | }, | ||||||||||||||
| 85 | => from 'Str' | ||||||||||||||
| 86 | => via { | ||||||||||||||
| 87 | 0 | ▶ | my $class = shift; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 88 | 0 | Class::Load::load_class( $class ); | |||||||||||||
| 89 | 0 | $class->new; | |||||||||||||
| 90 | }, | ||||||||||||||
| 91 | 49 | ; | |||||||||||||
| 92 | |||||||||||||||
| 93 | # SEEALSO: Magpie | ||||||||||||||
| 94 | |||||||||||||||
| 95 | 49 | 1; | |||||||||||||
| 96 | |||||||||||||||
| 97 | __END__ | ||||||||||||||
| 98 | =pod | ||||||||||||||
| 99 | |||||||||||||||
| 100 | =head1 NAME | ||||||||||||||
| 101 | |||||||||||||||
| 102 | Magpie::Types - Common Magpie Type Constraints | ||||||||||||||
| 103 | |||||||||||||||
| 104 | =head1 VERSION | ||||||||||||||
| 105 | |||||||||||||||
| 106 | version 1.141660 | ||||||||||||||
| 107 | |||||||||||||||
| 108 | =head1 AUTHORS | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =over 4 | ||||||||||||||
| 111 | |||||||||||||||
| 112 | =item * | ||||||||||||||
| 113 | |||||||||||||||
| 114 | Kip Hampton <kip.hampton@tamarou.com> | ||||||||||||||
| 115 | |||||||||||||||
| 116 | =item * | ||||||||||||||
| 117 | |||||||||||||||
| 118 | Chris Prather <chris.prather@tamarou.com> | ||||||||||||||
| 119 | |||||||||||||||
| 120 | =back | ||||||||||||||
| 121 | |||||||||||||||
| 122 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 123 | |||||||||||||||
| 124 | This software is copyright (c) 2011 by Tamarou, LLC. | ||||||||||||||
| 125 | |||||||||||||||
| 126 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 127 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 128 | |||||||||||||||
| 129 | =cut | ||||||||||||||
| 130 | |||||||||||||||