File Coverage

blib/lib/App/DuckPAN/Cmd/Publisher.pm
Criterion Covered Total %
statement 12 28 42.8
branch 0 10 0.0
condition n/a
subroutine 4 6 66.6
pod 0 1 0.0
total 16 45 35.5


line stmt bran cond sub pod time code
1             package App::DuckPAN::Cmd::Publisher;
2             our $AUTHORITY = 'cpan:DDG';
3             # ABSTRACT: Starting up the publisher test webserver
4             $App::DuckPAN::Cmd::Publisher::VERSION = '1017';
5 1     1   1514 use Moo;
  1         1  
  1         5  
6             with qw( App::DuckPAN::Cmd );
7              
8 1     1   220 use MooX::Options protect_argv => 0;
  1         1  
  1         6  
9 1     1   1048 use Path::Tiny;
  1         1  
  1         47  
10 1     1   500 use Plack::Handler::Starman;
  1         38277  
  1         264  
11              
12             for (qw( duckduckgo dontbubbleus donttrackus duckduckhack )) {
13             option $_ => (
14             is => 'ro',
15             format => 's',
16             predicate => 1,
17             );
18             }
19              
20             sub run {
21 0     0 0   my ( $self, @args ) = @_;
22              
23 0           $self->app->emit_info("Checking for Publisher...");
24              
25 0           my $publisher_pm = path('lib','DDG','Publisher.pm');
26 0 0         $self->app->emit_and_exit(1, "You must be in the root of the duckduckgo-publisher repository") unless $publisher_pm->exists;
27              
28 0           $self->app->emit_info("Starting up publisher webserver...", "You can stop the webserver with Ctrl-C");
29              
30 0 0         my %sites = (
    0          
    0          
    0          
31             duckduckgo => {
32             port => 5000,
33             url => $self->has_duckduckgo ? $self->duckduckgo : "http://duckduckgo.com/",
34             },
35             dontbubbleus => {
36             port => 5001,
37             url => $self->has_dontbubbleus ? $self->dontbubbleus : "http://dontbubble.us/",
38             },
39             donttrackus => {
40             port => 5002,
41             url => $self->has_donttrackus ? $self->donttrackus : "http://donttrack.us/",
42             },
43             duckduckhack => {
44             port => 5005,
45             url => $self->has_duckduckhack ? $self->duckduckhack : "http://duckduckhack.com/",
46             },
47             );
48              
49 0           for (sort { $sites{$a}->{port} <=> $sites{$b}->{port} } keys %sites) {
  0            
50 0           $self->app->emit_info("Serving on port ".$sites{$_}->{port}.": ".$sites{$_}->{url});
51             }
52              
53 0           require App::DuckPAN::WebPublisher;
54 0           my $web = App::DuckPAN::WebPublisher->new(
55             app => $self->app,
56             sites => \%sites,
57             );
58 0           my @ports = map { $sites{$_}->{port} } keys %sites;
  0            
59 0     0     exit Plack::Handler::Starman->new(listen => [ map { ":$_" } @ports ])->run(sub { $web->run_psgi(@_) });
  0            
  0            
60             }
61              
62             1;
63              
64             __END__
65              
66             =pod
67              
68             =head1 NAME
69              
70             App::DuckPAN::Cmd::Publisher - Starting up the publisher test webserver
71              
72             =head1 VERSION
73              
74             version 1017
75              
76             =head1 AUTHOR
77              
78             DuckDuckGo <open@duckduckgo.com>, Zach Thompson <zach@duckduckgo.com>, Zaahir Moolla <moollaza@duckduckgo.com>, Torsten Raudssus <torsten@raudss.us> L<https://raudss.us/>
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             This software is Copyright (c) 2013 by DuckDuckGo, Inc. L<https://duckduckgo.com/>.
83              
84             This is free software, licensed under:
85              
86             The Apache License, Version 2.0, January 2004
87              
88             =cut