| 1 | package FormValidator::Lite::Upload; | ||||||||||||||||||
| 2 | 30 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 3 | 30 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 30 | ▶ | use Carp (); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 30 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | { | ||||||||||||||||||
| 8 | 30 | my %cache; | |||||||||||||||||
| 9 | sub _load { | ||||||||||||||||||
| 10 | 11 | ▶ | my $pkg = shift; | ||||||||||||||||
|
Subroutine
_load: called CC=3 SCAR=11.0
| |||||||||||||||||||
| 11 | 11 | ▶ | unless ($cache{$pkg}++) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 12 | 3 | ▶ | eval "use $pkg"; ## no critic | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 13 | 3 | ▶ | Carp::croak($@) if $@; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 14 | } | ||||||||||||||||||
| 15 | 11 | $pkg; | |||||||||||||||||
| 16 | } | ||||||||||||||||||
| 17 | } | ||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 30 | sub new { | |||||||||||||||||
| 21 | 12 | ▶ | my ($self, $q, $name) = @_; | ||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=21.5
Pod
undocumented
| |||||||||||||||||||
| 22 | 12 | ▶ | Carp::croak("missing parameter \$name") unless $name; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 23 | 12 | ▶ | Carp::croak("\$q is not a object") unless blessed $q; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 12 | my $pkg = do { | |||||||||||||||||
| 26 | 12 | ▶ | if ($q->isa('CGI')) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 27 | 11 | 'CGI'; | |||||||||||||||||
| 28 | } elsif ($q->isa('HTTP::Engine::Request')) { | ||||||||||||||||||
| 29 | 0 | 'HTTPEngine'; | |||||||||||||||||
| 30 | } elsif ($q->isa('Plack::Request')) { | ||||||||||||||||||
| 31 | 0 | 'PlackRequest'; | |||||||||||||||||
| 32 | } else { | ||||||||||||||||||
| 33 | 1 | ▶ | if ($q->can('upload')){ # duck typing | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 34 | # this feature is needed by HTML::Shakan or other form validation libraries | ||||||||||||||||||
| 35 | 1 | return $q->upload($name); # special case :) | |||||||||||||||||
| 36 | } else { | ||||||||||||||||||
| 37 | 0 | die "unknown request type: $q"; | |||||||||||||||||
| 38 | } | ||||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | }; | ||||||||||||||||||
| 41 | 11 | $pkg = 'FormValidator::Lite::Upload::' . $pkg; | |||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | 11 | _load($pkg)->new($q, $name); | |||||||||||||||||
| 44 | } | ||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | 30 | 1; | |||||||||||||||||