EPublisher-Source-Plugin-PerltutsCom

 view release on metacpan or  search on metacpan

t/TestUA.pm  view on Meta::CPAN

package  # private package
    TestUA;

sub new {
    return bless {}, shift;
}

sub get {
    my ($ua, $url) = @_;

    my $error = q~HTTP/1.1 500 Internal Server Error
Content-Length: 21
Server: nginx
Date: Mon, 25 Feb 2019 15:04:37 GMT
Content-Type: text/plain
Connection: keep-alive

Internal Server Error
~;

     my $epublisher = q~HTTP/1.1 200 OK
Connection: keep-alive
Content-Disposition: attachment; filename=epublisher.pod
Server: nginx
Content-Type: application/octet-stream
Content-Length: 5632
Set-Cookie: plack_session=1551107060.11834%3ABQoDAAAAAQoCZW4AAAAYdHVybmFyb3VuZC5pMThuLmxhbmd1YWdl%3A318133c1d65f272af9e793495f0eebb084ed2d66; path=/; expires=Mon, 25-Feb-2019 15:54:20 GMT
Date: Mon, 25 Feb 2019 15:04:20 GMT

=head1 NAME

EPublisher
~;

     my $pdl = do{ local $/; <DATA> };

     my $response = $error;
     if ( $url =~ m{pdl}i ) {
         $response = $pdl;
     }
     elsif ( $url =~ m{epublisher}i ) {
         $response = $epublisher;
     }

     my ($header, $body)   = split /\n\n/, $response, 2;
     my ($status, $reason) = $header =~ m{HTTP/1\.1 \s+ ([0-9]+) \s+ ([^\n]+)}x;

     my $data = {
         status  => $status,
         content => $body,
         url     => $url,
         reason  => $reason,
     };

     return $data;
}

1;

__DATA__
HTTP/1.1 200 OK
Connection: keep-alive
Content-Disposition: attachment; filename=pdl.pod
Server: nginx
Content-Type: application/octet-stream
Content-Length: 5632
Set-Cookie: plack_session=1551107060.11834%3ABQoDAAAAAQoCZW4AAAAYdHVybmFyb3VuZC5pMThuLmxhbmd1YWdl%3A318133c1d65f272af9e793495f0eebb084ed2d66; path=/; expires=Mon, 25-Feb-2019 15:54:20 GMT
Date: Mon, 25 Feb 2019 15:04:20 GMT

=head1 NAME

PDL

=head1 INCLUDES

    /js/jquery.flot.min.js

=head1 JAVASCRIPT

    $('.test').after('<div class="plot hidden" style="margin-top:1em;width:600px;height:300px;"></div>');
    $.plot($('.plot'), []);

=head1 HANDLER

    (function(data) {
        var plot = $(form).children('.plot').first();
        $(plot).removeClass('hidden');
        if (data.result.constructor == Object && data.result.plot) {
            $.plot($(plot), data.result.plot);
        }
        else {
            $(plot).addClass('hidden');
            $.plot($(plot), []);
        }
    })(data);

=head1 MODULES

    PDL

=head1 PREAMBLE

    use PDL::LiteF;

    use Scalar::Util 'looks_like_number';

    sub plot {
        my @datasets = @_;

        my @output_datasets;
        for my $dataset (@datasets) {

            # promote to hashref
            unless (eval { ref $dataset eq 'HASH' }) {
                $dataset = {data => $dataset};
            }

            # 1D piddle
            if (eval { $dataset->{data}->isa('PDL') }) {
                $dataset->{data} =
                  [$dataset->{data}->sequence, $dataset->{data}];
            }



( run in 1.929 second using v1.01-cache-2.11-cpan-5735350b133 )