File Coverage

blib/lib/Dancer/Handler/Standalone.pm
Criterion Covered Total %
statement 27 53 50.9
branch 0 6 0.0
condition n/a
subroutine 9 12 75.0
pod 1 3 33.3
total 37 74 50.0


line stmt bran cond sub pod time code
1             package Dancer::Handler::Standalone;
2             our $AUTHORITY = 'cpan:SUKRIA';
3             # ABSTRACT: Web server wrapper for Dancer
4             $Dancer::Handler::Standalone::VERSION = '1.3520';
5 2     2   953 use strict;
  2         5  
  2         58  
6 2     2   11 use warnings;
  2         5  
  2         49  
7              
8 2     2   925 use HTTP::Server::Simple::PSGI;
  2         25934  
  2         80  
9 2     2   19 use base 'Dancer::Handler', 'HTTP::Server::Simple::PSGI';
  2         4  
  2         617  
10              
11 2     2   14 use Dancer::HTTP;
  2         6  
  2         84  
12 2     2   12 use Dancer::GetOpt;
  2         4  
  2         47  
13 2     2   10 use Dancer::Config 'setting';
  2         5  
  2         88  
14 2     2   13 use Dancer::FileUtils qw(read_glob_content);
  2         6  
  2         79  
15 2     2   11 use Dancer::SharedData;
  2         6  
  2         896  
16              
17             # in standalone mode, this method initializes the process
18             # and start an HTTP server
19             sub start {
20 0     0 0   my $self = shift;
21              
22 0           my $ipaddr = setting('server');
23 0           my $port = setting('port');
24 0           my $dancer = Dancer::Handler::Standalone->new($port);
25 0           $dancer->host($ipaddr);
26              
27 0           my $app = $self->psgi_app();
28              
29 0           $dancer->app($app);
30              
31 0 0         if (setting('daemon')) {
32 0           my $pid = $dancer->background();
33 0           print_startup_info($pid);
34 0           return $pid;
35             }
36             else {
37 0           print_startup_info($$);
38 0           $dancer->run();
39             }
40             }
41              
42             sub print_startup_info {
43 0     0 0   my $pid = shift;
44 0           my $ipaddr = setting('server');
45 0           my $port = setting('port');
46              
47             # we only print the info if we need to
48 0 0         setting('startup_info') or return;
49              
50             # bare minimum
51 0           print STDERR ">> Dancer $Dancer::VERSION server $pid listening " .
52             "on http://$ipaddr:$port\n";
53              
54             # all loaded plugins
55 0           foreach my $module ( grep { $_ =~ m{^Dancer/Plugin/} } keys %INC ) {
  0            
56 0           $module =~ s{/}{::}g; # change / to ::
57 0           $module =~ s{\.pm$}{}; # remove .pm at the end
58 0           my $version = $module->VERSION;
59              
60 0 0         defined $version or $version = 'no version number defined';
61 0           print ">> $module ($version)\n";
62             }
63              
64             }
65              
66             # Restore expected behavior for wait(), as
67             # HTTP::Server::Simple sets SIGCHLD to IGNORE.
68             # (Issue #499)
69             sub after_setup_listener {
70 0     0 1   $SIG{CHLD} = '';
71             }
72              
73             1;
74              
75             __END__