| 1 | package Dancer::Handler::Standalone; | ||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:SUKRIA'; | |||||||||
| 3 | # ABSTRACT: Web server wrapper for Dancer | ||||||||||
| 4 | 3 | $Dancer::Handler::Standalone::VERSION = '1.3520'; | |||||||||
| 5 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use HTTP::Server::Simple::PSGI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use base 'Dancer::Handler', 'HTTP::Server::Simple::PSGI'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | use Dancer::HTTP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 3 | ▶ | use Dancer::GetOpt; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 3 | ▶ | use Dancer::Config 'setting'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 3 | ▶ | use Dancer::FileUtils qw(read_glob_content); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 3 | ▶ | use Dancer::SharedData; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | # in standalone mode, this method initializes the process | ||||||||||
| 18 | # and start an HTTP server | ||||||||||
| 19 | sub start { | ||||||||||
| 20 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
start: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 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 | ▶ | if (setting('daemon')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | my $pid = shift; | ||||||||
|
Subroutine
print_startup_info: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 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 | ▶ | setting('startup_info') or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 ) { | |||||||||
| 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 | ▶ | defined $version or $version = 'no version number defined'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | $SIG{CHLD} = ''; | ||||||||
|
Subroutine
after_setup_listener: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 3 | 1; | |||||||||
| 74 | |||||||||||
| 75 | __END__ | ||||||||||