File Coverage

blib/lib/App/SimpleHTTPServer.pm
Criterion Covered Total %
statement 23 23 100.0
branch 4 8 50.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 32 36 88.8


line stmt bran cond sub pod time code
1 1     1   614 use strict;
  1         2  
  1         33  
2 1     1   3 use warnings;
  1         1  
  1         34  
3             package App::SimpleHTTPServer;
4              
5             # ABSTRACT: Serve up a directory via http simply and easily
6 1     1   518 use Mojolicious::Lite;
  1         102526  
  1         6  
7 1     1   16860 use Scalar::Util qw/ looks_like_number /;
  1         2  
  1         215  
8              
9             our $TESTING = 0;
10              
11             sub import {
12 1     1   331 my $package = shift;
13 1         2 my $port = shift;
14 1 50       6 if (not looks_like_number $port) {
15 1 50       2 unshift @_, $port if defined $port;
16 1         2 $port = 8000;
17             }
18 1         1 my $path = shift;
19 1 50       2 $path = '.' unless defined $path;
20              
21 1         3 plugin Directory => root => $path;
22              
23 1         3532 my @args = (qw/ daemon -l /, "http://*:$port/");
24 1 50       5 @args = (qw/ eval /) if $TESTING; # For testing, it needs something to
25             # do so it doesn't display help message
26              
27 1         3 app->start(@args);
28             }
29              
30             1;