2008年11月26日

HECon前の前菜に最適だったので。
404 Blog Not Found:perl - LWP::UserAgentで進捗表示しつつダウンロード
というかHECon1は参加条件緩めたしまだあと10名程来れるので是非是非きて下さい。発表枠も1-2枠くらい余ってます。Shibuya.pmの前夜祭的な参加もおkす。

で、何をやったかというとファイルアップロードされるとプログレスバーを表示する。
ServerSimpleやPOE向きの実装。
これを使う事によりアップロードされまくってる感が増大します。しかも簡単なhackで済んでるところも素敵ですね。

こんな感じにコンソール出力されます。

$ perl ./http-engine-progressbar.pl
HTTP::Server::Simple: You can connect to your server at http://localhost:1978/
Upload[15774168]: 100% [=========================================================================================================]D 0h00m04s

use strict;
use warnings;
use HTTP::Engine;
use Term::ProgressBar;

my $engine = HTTP::Engine->new(
    interface => {
        module => 'ServerSimple',
        args   => { port => 1978 },
        request_handler => sub {
            my $req = shift;

            return HTTP::Engine::Response->new(
                body => q|<form method="post" enctype="multipart/form-data">
                          <input type="file" name="upload_file" />
                          <input type="submit" />
                          </form>|
            ) unless $req->param('file');
        },
    }
);

{
    my $progress;
    my $content_length = 0;
    my $read_size      = 0;
    $engine->interface->request_builder->meta->make_mutable;
    $engine->interface->request_builder->meta->add_before_method_modifier(
        _read_init => sub {
            my($self, $args) = @_;
            return unless $content_length = $args->{content_length};
            $read_size = 0;
            $progress = Term::ProgressBar->new({
                count => $content_length,
                name  => "Upload[$content_length]",
                ETA   => 'linear',
            });
        },
    );
    if (1) {
        $engine->interface->request_builder->meta->add_around_method_modifier(
            _read_chunk => sub {
                my $next = shift;
                my $size = $next->(@_);
                $read_size += $size;
                $progress->update($read_size);
                return $size;
            },
        );
    }
    $engine->interface->request_builder->meta->add_after_method_modifier(
        _read_to_end => sub {
            return unless $content_length;
            $content_length = 0;
            $read_size      = 0;
        },
    );
    $engine->interface->request_builder->meta->make_immutable;
}

$engine->run;

Posted by Yappo at 2008年11月26日 12:04 | TrackBack | Perl
Comments

iPhone and others cell phoen accessories oem china keypads I believe Dave is vital to my college success thus far the nokia covers are now accepting entries for the second annual cell phone keypads. The heat recognizes college journalists cell phone covers reporting in their college print, television or online,radio, so onNokia Cell Phone Nokia 6085 Case, Cables, Nokia cell phone housing Buy Nokia cell phone accessories like Nokia batteries, cases, faceplates more at discounted prices only at Wireless nokia keypads the #1lg keypads phone nokia nokia faceplates college journalists which demonstrate outstanding samsung keypads reporting in their college print, television or online,radio, Sony Ericsson keypads supportive adviser I have had. oem china keypads Because he cares Sony Ericsson covers Give your phone different varieties of styles and motorola keypads. our cell phone keypads are easy to install and won’t take up too samsung covers of your time. Choose motorola covers from the range of mobile buttons and keypads afforded on our site.lg covers are certain you will certainly find something suiting your needs and taste. We say with confidence keypads and cover housing ,and faceplates sony ericsson

Posted by: cell phone housing at 2009年06月28日 21:21
Post a comment









Remember personal info?






コメントを投稿する前に↓の場所にnospamと入力してください。