blib/lib/Marky.pm

filter: Statementstmt 50.0% 31 / 62 Branchbran 35.7% 5 / 14 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 46.3% 44 / 95 SCAR 36.8
CC
13
Cov
46%
startup
53.6
BEGIN
1.0
BEGIN
1.0
CRAP 39.8
« blib/lib/Marky/Bookmarker.pm ↑ Summary Build »
1 package Marky;
2 2 $Marky::VERSION = '0.034';
3 # ABSTRACT: web application for bookmark databases
4  
5 2 ▶use Mojo::Base 'Mojolicious';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # This method will run once at server start
10 sub startup {
11 1 ▶ my $self = shift;
Subroutine startup: called CC=13 SCAR=39.8
Pod documented
12  
13 # -------------------------------------------
14 # Configuration
15 # check:
16 # * current working directory
17 # * relative to the calling program
18 # -------------------------------------------
19 1 my $the_prog = path($0)->absolute;
20 1 my $conf_basename = "marky.conf";
21 1 my $conf_file = path(Path::Tiny->cwd, $conf_basename);
22 1 ▶ if (! -f $conf_file)
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $conf_file) 0 1 1
23 {
24 0 $conf_file = path($the_prog->parent->stringify, $conf_basename);
25 0 ▶ if (! -f $conf_file)
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $conf_file) 0 0 0
26 {
27 0 $conf_file = path($the_prog->parent->parent->stringify, $conf_basename);
28 }
29 }
30 # the MARKY_CONFIG environment variable overrides the default
31 1 ▶ if (defined $ENV{MARKY_CONFIG} and -f $ENV{MARKY_CONFIG})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"MARKY_CONFIG"} and -f $ENV{"MARKY_CONFIG"}) 0 1 1
Condition33%1/3
defined $ENV{"MARKY_CONFIG"} and -f $ENV{"MARKY_CONFIG"}
!ll&&!rl&&r
100
MC/DC0%0/2
defined $ENV{"MARKY_CONFIG"} and -f $ENV{"MARKY_CONFIG"}
defined $ENV{"MARKY_CONFIG"} -f $ENV{"MARKY_CONFIG"}
Truth table33%1/3
A and B
A= defined $ENV{"MARKY_CONFIG"}B= -f $ENV{"MARKY_CONFIG"}
ABresult
0X0
100
111
32 {
33 0 $conf_file = $ENV{MARKY_CONFIG};
34 }
35 1 print STDERR "CONFIG: $conf_file\n";
36 1 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 ▶ if (defined $mojo_config->{public_dir}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mojo_config->{"public_dir"} and $mojo_config->{"public_dir"} and -d $mojo_config->{"public_dir"}) 0 1 1
Condition33%2/6
defined $mojo_config->{"public_dir"} and $mojo_config->{"public_dir"} and -d $mojo_config->{"public_dir"}
!ll&&!rl&&r
100
defined $mojo_config->{"public_dir"} and $mojo_config->{"public_dir"}
!ll&&!rl&&r
100
MC/DC0%0/3
defined $mojo_config->{"public_dir"} and $mojo_config->{"public_dir"} and -d $mojo_config->{"public_dir"}
defined $mojo_config->{"public_dir"} $mojo_config->{"public_dir"} -d $mojo_config->{"public_dir"}
Truth table25%1/4
A and B and C
A= defined $mojo_config->{"public_dir"}B= $mojo_config->{"public_dir"}C= -d $mojo_config->{"public_dir"}
ABCresult
0XX0
10X0
1100
1111
46 and $mojo_config->{public_dir}
47 and -d $mojo_config->{public_dir})
48 {
49 0 push @{$self->static->paths}, $mojo_config->{public_dir};
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 my $pubdir = path(Path::Tiny->cwd, "public");
59 1 ▶ if (!-d $pubdir)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $pubdir) 0 1 1
60 {
61 0 $pubdir = path($the_prog->parent->stringify, "public");
62 0 ▶ if (!-d $pubdir)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $pubdir) 0 0 0
63 {
64 # use File::ShareDir with the distribution name
65 0 my $dist = __PACKAGE__;
66 0 $dist =~ s/::/-/g;
67 0 my $dist_dir = path(File::ShareDir::dist_dir($dist));
68 0 $pubdir = $dist_dir;
69 }
70 }
71 1 ▶ if (-d $pubdir)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $pubdir) 1 0 1
72 {
73 1 push @{$self->static->paths}, $pubdir;
74 }
75
76 # -------------------------------------------
77 # DB Tables and Foil
78 # -------------------------------------------
79 1 $self->plugin('Marky::DbTableSet');
80  
81 1 my @db_routes = ();
82 1 foreach my $db (@{$self->marky_table_array})
83 {
84 1 push @db_routes, "/db/$db";
85 }
86 1 $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__;
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}})
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 2 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 <perlkat@katspace.org>
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__
« blib/lib/Marky/Bookmarker.pm ↑ Summary Build »