| 1 | package Net::Curl::Simple::Form; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Scalar::Util qw(looks_like_number); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 0 | ▶ | use Net::Curl::Form; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | use base qw(Net::Curl::Form); | ||
| 8 | |||
| 9 | our $VERSION = '0.13'; | ||
| 10 | |||
| 11 | { | ||
| 12 | my %optcache; | ||
| 13 | |||
| 14 | sub add | ||
| 15 | { | ||
| 16 | my $form = shift; | ||
| 17 | |||
| 18 | my @args; | ||
| 19 | while ( my ( $opt, $val ) = splice @_, 0, 2 ) { | ||
| 20 | unless ( looks_like_number( $opt ) ) { | ||
| 21 | # convert option name to option number | ||
| 22 | unless ( exists $optcache{ $opt } ) { | ||
| 23 | eval '$optcache{ $opt } = ' | ||
| 24 | . "Net::Curl::Form::CURLFORM_COPY\U$opt"; | ||
| 25 | eval '$optcache{ $opt } = ' | ||
| 26 | . "Net::Curl::Form::CURLFORM_\U$opt" | ||
| 27 | if $@; | ||
| 28 | die "unrecognized literal option: $opt\n" | ||
| 29 | if $@; | ||
| 30 | } | ||
| 31 | $opt = $optcache{ $opt }; | ||
| 32 | } | ||
| 33 | |||
| 34 | push @args, $opt, $val; | ||
| 35 | } | ||
| 36 | |||
| 37 | $form->SUPER::add( @args ); | ||
| 38 | |||
| 39 | # allow chaining | ||
| 40 | return $form; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | sub contents | ||
| 45 | { | ||
| 46 | my ( $form, $name, $contents ) = @_; | ||
| 47 | $form->add( name => $name, contents => $contents ); | ||
| 48 | } | ||
| 49 | |||
| 50 | sub file | ||
| 51 | { | ||
| 52 | my $form = shift; | ||
| 53 | $form->add( name => shift, map +( file => $_ ), @_ ); | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; | ||
| 57 | |||
| 58 | __END__ | ||