File Coverage

blib/lib/Marky.pm
Criterion Covered Total %
statement 29 60 48.3
branch 4 14 28.5
condition 2 9 22.2
subroutine 4 4 100.0
pod 1 1 100.0
total 40 88 45.4


line stmt bran cond sub pod time code
1             package Marky;
2             $Marky::VERSION = '0.034';
3             # ABSTRACT: web application for bookmark databases
4              
5 1     1   521 use Mojo::Base 'Mojolicious';
  1         3  
  1         10  
6 1     1   39043 use Path::Tiny;
  1         9567  
  1         68  
7 1     1   365 use File::ShareDir;
  1         4514  
  1         616  
8              
9             # This method will run once at server start
10             sub startup {
11 1     1 1 11045 my $self = shift;
12              
13             # -------------------------------------------
14             # Configuration
15             # check:
16             # * current working directory
17             # * relative to the calling program
18             # -------------------------------------------
19 1         7 my $the_prog = path($0)->absolute;
20 1         173 my $conf_basename = "marky.conf";
21 1         7 my $conf_file = path(Path::Tiny->cwd, $conf_basename);
22 1 50       83 if (! -f $conf_file)
23             {
24 0         0 $conf_file = path($the_prog->parent->stringify, $conf_basename);
25 0 0       0 if (! -f $conf_file)
26             {
27 0         0 $conf_file = path($the_prog->parent->parent->stringify, $conf_basename);
28             }
29             }
30             # the MARKY_CONFIG environment variable overrides the default
31 1 50 33     24 if (defined $ENV{MARKY_CONFIG} and -f $ENV{MARKY_CONFIG})
32             {
33 0         0 $conf_file = $ENV{MARKY_CONFIG};
34             }
35 1         4 print STDERR "CONFIG: $conf_file\n";
36 1         56 my $mojo_config = $self->plugin('Config' => { file => $conf_file });
37              
38             # -------------------------------------------
39             # Application public directory
40             #
41             # For doing things like displaying images; the most portable method of
42             # doing this is to have a "local" public directory which has softlinks to
43             # the various desired directories.
44             # -------------------------------------------
45 1 0 33     3817 if (defined $mojo_config->{public_dir}
      0        
46             and $mojo_config->{public_dir}
47             and -d $mojo_config->{public_dir})
48             {
49 0         0 push @{$self->static->paths}, $mojo_config->{public_dir};
  0         0  
50             }
51              
52             # -------------------------------------------
53             # Append Marky public directory
54             # Find the Marky "public" directory
55             # It could be relative to the CWD
56             # It could be relative to the calling program
57             # It could be in a FileShared location.
58 1         8 my $pubdir = path(Path::Tiny->cwd, "public");
59 1 50       73 if (!-d $pubdir)
60             {
61 0         0 $pubdir = path($the_prog->parent->stringify, "public");
62 0 0       0 if (!-d $pubdir)
63             {
64             # use File::ShareDir with the distribution name
65 0         0 my $dist = __PACKAGE__;
66 0         0 $dist =~ s/::/-/g;
67 0         0 my $dist_dir = path(File::ShareDir::dist_dir($dist));
68 0         0 $pubdir = $dist_dir;
69             }
70             }
71 1 50       18 if (-d $pubdir)
72             {
73 1         16 push @{$self->static->paths}, $pubdir;
  1         11  
74             }
75            
76             # -------------------------------------------
77             # DB Tables and Foil
78             # -------------------------------------------
79 1         22 $self->plugin('Marky::DbTableSet');
80              
81 1         32 my @db_routes = ();
82 1         3 foreach my $db (@{$self->marky_table_array})
  1         23  
83             {
84 1         5 push @db_routes, "/db/$db";
85             }
86 1         8 $self->plugin('Foil' => { add_prefixes => \@db_routes});
87              
88 0           $self->plugin(NYTProf => $mojo_config);
89              
90             # -------------------------------------------
91             # Templates
92             # -------------------------------------------
93 0           push @{$self->renderer->classes}, __PACKAGE__;
  0            
94              
95             # -------------------------------------------
96             # secrets, cookies and defaults
97             # -------------------------------------------
98 0           $self->secrets([qw(etunAvIlyiejUnnodwyk supernumary55)]);
99 0           $self->sessions->cookie_name('marky');
100 0           $self->sessions->default_expiration(60 * 60 * 24 * 3); # 3 days
101 0           foreach my $key (keys %{$self->config->{defaults}})
  0            
102             {
103 0           $self->defaults($key, $self->config->{defaults}->{$key});
104             }
105              
106             # -------------------------------------------
107              
108             # -------------------------------------------
109             # Router
110             # -------------------------------------------
111 0           my $r = $self->routes;
112              
113 0           $r->get('/')->to('db#tables');
114 0           $r->get('/opt')->to('db#options');
115 0           $r->get('/db/:db/opt')->to('db#options');
116              
117 0           $r->get('/db/:db/taglist')->to('db#taglist');
118 0           $r->get('/db/:db/tagcloud')->to('db#tagcloud');
119              
120 0           $r->get('/db/:db')->to('db#query');
121 0           $r->get('/db/:db/tags/:tags')->to('db#tags');
122              
123 0           $r->get('/db/:db/add')->to('db#add_bookmark');
124 0           $r->post('/db/:db/add')->to('db#save_bookmark');
125             }
126              
127             1; # end of Marky
128              
129             # Here come the TEMPLATES!
130              
131             =pod
132              
133             =encoding UTF-8
134              
135             =head1 NAME
136              
137             Marky - web application for bookmark databases
138              
139             =head1 VERSION
140              
141             version 0.034
142              
143             =head1 SYNOPSIS
144              
145             use Marky;
146              
147             =head1 DESCRIPTION
148              
149             Bookmarking and Tutorial Library application.
150             This uses
151             Mojolicious
152             Mojolicious::Plugin::Foil
153              
154             Font Awesome by Dave Gandy - http://fontawesome.io
155              
156             =head1 NAME
157              
158             Marky - web application for bookmark databases
159              
160             =head1 VERSION
161              
162             version 0.034
163              
164             =head1 AUTHOR
165              
166             Kathryn Andersen
167              
168             =head1 COPYRIGHT AND LICENSE
169              
170             This software is copyright (c) 2017 by Kathryn Andersen.
171              
172             This is free software; you can redistribute it and/or modify it under
173             the same terms as the Perl 5 programming language system itself.
174              
175             =cut
176              
177             __DATA__