| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package App::SimpleHTTPServer; | ||||||||||
| 4 | 1 | $App::SimpleHTTPServer::VERSION = '0.002'; | |||||||||
| 5 | # ABSTRACT: Serve up a directory via http simply and easily | ||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | BEGIN { @ARGV = qw/ -m production /; } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Mojolicious::Lite; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Scalar::Util qw/ looks_like_number /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | our $TESTING = 0; | |||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=5 SCAR=16.3
| |||||||||||
| 14 | 1 | my $package = shift; | |||||||||
| 15 | 1 | my $port = shift; | |||||||||
| 16 | 1 | ▶ | if (not looks_like_number $port) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 1 | ▶ | unshift @_, $port if defined $port; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 1 | $port = 8000; | |||||||||
| 19 | } | ||||||||||
| 20 | 1 | my $path = shift; | |||||||||
| 21 | 1 | ▶ | $path = '.' unless defined $path; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | 1 | push @{ app->renderer->classes }, __PACKAGE__; | |||||||||
| 24 | 1 | push @{ app->static->classes }, __PACKAGE__; | |||||||||
| 25 | |||||||||||
| 26 | 1 | plugin 'Directory::Stylish' => root => $path; | |||||||||
| 27 | |||||||||||
| 28 | 1 | my @args = (qw/ daemon -l /, "http://*:$port/"); | |||||||||
| 29 | 1 | ▶ | @args = (qw/ eval /) if $TESTING; # For testing, it needs something to | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | # do so it doesn't display help message | ||||||||||
| 31 | |||||||||||
| 32 | 1 | app->secrets([qw/ foo /]); | |||||||||
| 33 | 1 | app->start(@args); | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 1 | 1; | |||||||||
| 37 | |||||||||||
| 38 | =pod | ||||||||||
| 39 | |||||||||||
| 40 | =encoding UTF-8 | ||||||||||
| 41 | |||||||||||
| 42 | =head1 NAME | ||||||||||
| 43 | |||||||||||
| 44 | App::SimpleHTTPServer - Serve up a directory via http simply and easily | ||||||||||
| 45 | |||||||||||
| 46 | =head1 VERSION | ||||||||||
| 47 | |||||||||||
| 48 | version 0.002 | ||||||||||
| 49 | |||||||||||
| 50 | =head1 SYNOPSIS | ||||||||||
| 51 | |||||||||||
| 52 | $ # To serve the current directory via http on port 8000, simply do: | ||||||||||
| 53 | $ perl -MApp::SimpleHTTPServer | ||||||||||
| 54 | |||||||||||
| 55 | $ # or use the serve_dir script: | ||||||||||
| 56 | $ serve_dir | ||||||||||
| 57 | |||||||||||
| 58 | =head1 SEE ALSO | ||||||||||
| 59 | |||||||||||
| 60 | L<Mojolicious> - The Mojolicious web framework | ||||||||||
| 61 | |||||||||||
| 62 | L<Mojolicious::Plugin::Directory::Stylish> - The module that actually renders | ||||||||||
| 63 | the directory listing | ||||||||||
| 64 | |||||||||||
| 65 | =head1 AUTHOR | ||||||||||
| 66 | |||||||||||
| 67 | Andreas Guldstrand <andreas.guldstrand@gmail.com> | ||||||||||
| 68 | |||||||||||
| 69 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 70 | |||||||||||
| 71 | This software is Copyright (c) 2015 by Andreas Guldstrand. | ||||||||||
| 72 | |||||||||||
| 73 | This is free software, licensed under: | ||||||||||
| 74 | |||||||||||
| 75 | The MIT (X11) License | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | __DATA__ | ||||||||||