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