├── .gitignore ├── t ├── myapp.par ├── 00_compile.t └── par.t ├── .shipit ├── Changes ├── xt └── pod.t ├── MANIFEST.SKIP ├── Makefile.PL ├── MANIFEST ├── README └── lib └── Plack └── App └── PAR.pm /.gitignore: -------------------------------------------------------------------------------- 1 | META.yml 2 | Makefile 3 | inc/ 4 | pm_to_blib 5 | *~ 6 | -------------------------------------------------------------------------------- /t/myapp.par: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miyagawa/Plack-App-PAR/HEAD/t/myapp.par -------------------------------------------------------------------------------- /t/00_compile.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use Test::More tests => 1; 3 | 4 | BEGIN { use_ok 'Plack::App::PAR' } 5 | -------------------------------------------------------------------------------- /.shipit: -------------------------------------------------------------------------------- 1 | steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN 2 | git.push_to = origin 3 | -------------------------------------------------------------------------------- /Changes: -------------------------------------------------------------------------------- 1 | Revision history for Perl extension Plack::App::PAR 2 | 3 | 0.01 Thu Mar 24 14:53:25 2011 4 | - original version 5 | -------------------------------------------------------------------------------- /xt/pod.t: -------------------------------------------------------------------------------- 1 | use Test::More; 2 | eval "use Test::Pod 1.00"; 3 | plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; 4 | all_pod_files_ok(); 5 | -------------------------------------------------------------------------------- /MANIFEST.SKIP: -------------------------------------------------------------------------------- 1 | \bRCS\b 2 | \bCVS\b 3 | \.svn/ 4 | \.git/ 5 | ^MANIFEST\. 6 | ^Makefile$ 7 | ~$ 8 | \.old$ 9 | ^blib/ 10 | ^pm_to_blib 11 | ^MakeMaker-\d 12 | \.gz$ 13 | \.cvsignore 14 | \.shipit 15 | -------------------------------------------------------------------------------- /Makefile.PL: -------------------------------------------------------------------------------- 1 | use inc::Module::Install; 2 | all_from 'lib/Plack/App/PAR.pm'; 3 | readme_from('lib/Plack/App/PAR.pm'); 4 | 5 | requires 'PAR', 1.000; 6 | requires 'Plack', 0.9970; 7 | 8 | build_requires 'Test::More', 0.88; 9 | test_requires 'Test::Requires'; 10 | auto_set_repository(); 11 | WriteAll; 12 | -------------------------------------------------------------------------------- /t/par.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use Test::More; 3 | 4 | use Plack::Test; 5 | use Plack::App::PAR; 6 | use HTTP::Request::Common; 7 | 8 | my $app = Plack::App::PAR->new(file => "t/MyApp.par")->to_app; 9 | 10 | test_psgi $app, sub { 11 | my $cb = shift; 12 | 13 | my $res = $cb->(GET "/"); 14 | like $res->content, qr/Hello/; 15 | }; 16 | 17 | done_testing; 18 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | .gitignore 2 | Changes 3 | inc/Module/Install.pm 4 | inc/Module/Install/Base.pm 5 | inc/Module/Install/Can.pm 6 | inc/Module/Install/Fetch.pm 7 | inc/Module/Install/Makefile.pm 8 | inc/Module/Install/Metadata.pm 9 | inc/Module/Install/ReadmeFromPod.pm 10 | inc/Module/Install/Repository.pm 11 | inc/Module/Install/Win32.pm 12 | inc/Module/Install/WriteAll.pm 13 | lib/Plack/App/PAR.pm 14 | Makefile.PL 15 | MANIFEST This list of files 16 | META.yml 17 | README 18 | t/00_compile.t 19 | xt/pod.t 20 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | NAME 2 | Plack::App::PAR - Run .par bundle as a PSGI application 3 | 4 | SYNOPSIS 5 | % plackup -MPlack::App::PAR -e 'Plack::App::PAR->new(file => "/path/to/myapp.par")->to_app' 6 | 7 | DESCRIPTION 8 | Plack::App::PAR is a Plack endpoint to run PAR bundle as a PSGI 9 | application. 10 | 11 | You can use the standard .par files - the only restriction is that you 12 | have to have an *entry point* PSGI script file as a "app.psgi" inside 13 | "script" directory (which can be changed with the "script" option - see 14 | below). 15 | 16 | % pp -I lib -p -o myapp.par app.psgi 17 | 18 | This will create a "myapp.par" bundle with "app.psgi" as an entry point. 19 | 20 | WHY? 21 | Inspired by 22 | :) 24 | 25 | OPTIONS 26 | file 27 | The path to the PAR archive file you want to run. Required. 28 | 29 | script 30 | The name of the entry point script inside the PAR archive. 31 | "script/app.psgi" by default. 32 | 33 | TODO/BUGS 34 | * There's no cleaner way to locate non-perl library files, for example 35 | static files directory to use for Static middleware path. I guess 36 | File::ShareDir::PAR could be used. 37 | 38 | * I'm not sure what happens if you instantiate multiple applications 39 | of this class for multiple .par files in the same web server 40 | process. Because PAR's interface is based on "import", I won't be 41 | surprised if you get an unexpected result. 42 | 43 | AUTHOR 44 | Tatsuhiko Miyagawa 45 | 46 | COPYRIGHT 47 | Copyright 2011- Tatsuhiko Miyagawa 48 | 49 | LICENSE 50 | This library is free software; you can redistribute it and/or modify it 51 | under the same terms as Perl itself. 52 | 53 | SEE ALSO 54 | PAR 55 | 56 | -------------------------------------------------------------------------------- /lib/Plack/App/PAR.pm: -------------------------------------------------------------------------------- 1 | package Plack::App::PAR; 2 | 3 | use strict; 4 | use 5.008_001; 5 | our $VERSION = '0.01'; 6 | 7 | use parent qw(Plack::Component); 8 | use Plack::Util::Accessor qw( file script ); 9 | use Carp (); 10 | use PAR (); 11 | 12 | sub prepare_app { 13 | my $self = shift; 14 | 15 | my $file = $self->file or Carp::croak "'file' is not set"; 16 | my $script = $self->script || "app.psgi"; 17 | 18 | PAR->import({ file => $file }); 19 | my $zip = PAR::par_handle($file); 20 | 21 | my $member = PAR::_first_member($zip, "script/$script", $script); 22 | 23 | my($fh, $is_new, $filename) = PAR::_tempfile($member->crc32String . ".psgi"); 24 | 25 | if ($is_new) { 26 | my $file = $member->fileName; 27 | print $fh "#line 1 \"$file\"\n"; 28 | $member->extractToFileHandle($fh); 29 | seek $fh, 0, 0; 30 | } 31 | 32 | $self->{_app} = Plack::Util::load_psgi($filename); 33 | } 34 | 35 | sub call { 36 | my($self, $env) = @_; 37 | $self->{_app}->($env); 38 | } 39 | 40 | 1; 41 | __END__ 42 | 43 | =encoding utf-8 44 | 45 | =for stopwords 46 | 47 | =head1 NAME 48 | 49 | Plack::App::PAR - Run .par bundle as a PSGI application 50 | 51 | =head1 SYNOPSIS 52 | 53 | % plackup -MPlack::App::PAR -e 'Plack::App::PAR->new(file => "/path/to/myapp.par")->to_app' 54 | 55 | =head1 DESCRIPTION 56 | 57 | Plack::App::PAR is a Plack endpoint to run L bundle as a PSGI 58 | application. 59 | 60 | You can use the standard .par files - the only restriction is that you 61 | have to have an I PSGI script file as a C 62 | either in the root or inside C