++ed by:

1 PAUSE user
2 non-PAUSE users.

Author image MATSUNO★…Tokuhiro
and 3 contributors


HTTP::Body::Builder::MultiPart - multipart/form-data


    use HTTP::Body::Builder::MultiPart;

    my $builder = HTTP::Body::Builder::MultiPart->new();
    $builder->add_content('x' => 'y');
    # => x=y


my $builder = HTTP::Body::Builder::MultiPart->new()

Create a new HTTP::Body::Builder::MultiPart instance.

The constructor accepts named arguments as a hash. The allowed parameters are content and files. Each of these parameters should in turn be a hashref.

For the content parameter, each key/value pair in this hashref will be added to the builder by calling the add_content method.

For the files parameter, the keys are parameter names and the values are filenames.

If the value of one of the content hashref's keys is an arrayref, then each member of the arrayref will be added separately.

        content => {'a' => 42, 'b' => [1, 2]},
        files   => {'x' => 'path/to/file'},

is equivalent to the following:

    my $builder = HTTP::Body::Builder::MultiPart->new;
    $builder->add_content('a' => 42);
    $builder->add_content('b' => 1);
    $builder->add_content('b' => 2);
    $builder->add_files('x' => 'path/to/file');
$builder->add_content($key => $value);

Add new parameter in raw string.

$builder->add_file($key => $real_file_name);

Add $real_file_name as $key.


Generate body as string.


Write the content to $filename.