Marky.pm

filter: Statementstmt 53.4% 31 / 58 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 48.3% 44 / 91 CC 13 SCAR 37.0
CC
13
Cov
48%
startup
49.5
BEGIN
1.0
BEGIN
1.0
CRAP 40.4
« Marky/DbTable.pm ↑ Summary Marky/Bookmarker.pm »
1 package Marky;
2 2 $Marky::VERSION = '0.0604';
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 1 ▶sub startup {
Subroutine startup: called CC=13 SCAR=39.0
Pod documented
11 1 my $self = shift;
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 "Marky::VERSION=$Marky::VERSION 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 #$self->plugin(NYTProf => $mojo_config);
89  
90 # -------------------------------------------
91 # Templates
92 # -------------------------------------------
93 0 push @{$self->renderer->classes}, __PACKAGE__;
94  
95 # -------------------------------------------
96 # secrets, and defaults
97 # -------------------------------------------
98 0 $self->secrets([qw(AUygaywzatNJ9maaN3XY etunAvIlyiejUnnodwyk supernumary55)]);
99 #$self->sessions->cookie_name('marky');
100 #$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('/db/')->to('db#tables');
115  
116 0 $r->get('/db/:db/taglist')->to('db#taglist');
117 0 $r->get('/db/:db/tagcloud')->to('db#tagcloud');
118  
119 0 $r->get('/db/:db')->to('db#query');
120 0 $r->get('/db/:db/tags/:tags')->to('db#tags');
121  
122 0 $r->get('/db/:db/add')->to('db#add_bookmark');
123 0 $r->post('/db/:db/add')->to('db#save_bookmark');
124 }
125  
126 2 1; # end of Marky
127  
128 # Here come the TEMPLATES!
129  
130 =pod
131  
132 =encoding UTF-8
133  
134 =head1 NAME
135  
136 Marky - web application for bookmark databases
137  
138 =head1 VERSION
139  
140 version 0.0604
141  
142 =head1 SYNOPSIS
143  
144 use Marky;
145  
146 =head1 DESCRIPTION
147  
148 Bookmarking and Tutorial Library application.
149 This uses
150 Mojolicious
151 Mojolicious::Plugin::Foil
152  
153 Font Awesome by Dave Gandy - http://fontawesome.io
154  
155 =head1 NAME
156  
157 Marky - web application for bookmark databases
158  
159 =head1 VERSION
160  
161 version 0.0604
162  
163 =head1 AUTHOR
164  
165 Kathryn Andersen <perlkat@katspace.org>
166  
167 =head1 COPYRIGHT AND LICENSE
168  
169 This software is copyright (c) 2017 by Kathryn Andersen.
170  
171 This is free software; you can redistribute it and/or modify it under
172 the same terms as the Perl 5 programming language system itself.
173  
174 =cut
175  
176 __DATA__
« Marky/DbTable.pm ↑ Summary Marky/Bookmarker.pm »