Zapp

 view release on metacpan or  search on metacpan

lib/Zapp/Task/Request.pm  view on Meta::CPAN

        \%headers,
        $input->{content_type} ? ( $body ) : (),
    );
    $tx = $ua->start( $tx );
    # ; use Data::Dumper;
    # ; say Dumper $tx->res;
    my $method = !$tx->res->error ? 'finish' : 'fail';

    my @res_body;
    if ( $tx->res->headers->content_type eq 'application/octet-stream' ) {
        my ( $filename ) = grep !!$_, reverse split m{/}, $input->{url};
        if ( $tx->res->headers->content_disposition =~ m{filename\*?=['"]?([^'"]+)['"]?} ) {
            $filename = $1;
        }
        my $path = $self->app->static->paths->[0];
        my $file = Mojo::File->new( $path, 'task', 'request', $self->id, $filename );
        $file->dirname->make_path;
        $file->spurt( $tx->res->body );
        @res_body = (
            file => '/' . $file->to_rel( $self->app->home->child( 'public' ) ),
        );

t/type/file.t  view on Meta::CPAN

subtest 'process_input' => sub {
    my $c = $t->app->build_controller;
    my $upload = Mojo::Upload->new(
        filename => 'foo.txt',
        asset => Mojo::Asset::Memory->new->add_chunk( 'Hello, World!' ),
        name => 'input[0].value',
    );
    my $type_value = $type->process_input( $c, undef, $upload );
    is $type_value, 'Cg/qf/KmdylCVXq1NV12r0Qvj2XgE/foo.txt',
        'form_input returns path';
    my $file = $temp->child( 'public', split m{/}, $type_value );
    ok -e $file, 'file exists';
    is $file->slurp, 'Hello, World!', 'file content is correct';

    subtest 'no default' => sub {
        my $upload = Mojo::Upload->new(
            filename => '',
            asset => Mojo::Asset::Memory->new->add_chunk( '' ),
            name => 'input[0].value',
        );
        my $type_value = $type->process_input( $c, undef, $upload );

t/type/file.t  view on Meta::CPAN

    is $task_value, $t->app->home->child( 'public', $type_value ),
        'task_value path is correct';
};

subtest 'task_output' => sub {
    my $tmp = tempfile()->spurt( 'Goodbye, World!' );
    my $task_value = "$tmp";
    my $type_value = $type->task_output( undef, $task_value );
    is $type_value, 'qj/OR/3yrB7CZSKh0leolWSXSF-nY/' . $tmp->basename,
        'type_value is correct';
    my $file = $t->app->home->child( 'public', split m{/}, $type_value );
    ok -e $file, 'file exists';
    is $file->slurp, 'Goodbye, World!', 'file content is correct';
};

done_testing;



( run in 0.432 second using v1.01-cache-2.11-cpan-71847e10f99 )