File Coverage

blib/lib/Mojo/Leds.pm
Criterion Covered Total %
statement 27 34 79.4
branch 4 12 33.3
condition 1 5 20.0
subroutine 4 4 100.0
pod 1 1 100.0
total 37 56 66.0


line stmt bran cond sub pod time code
1             package Mojo::Leds;
2             $Mojo::Leds::VERSION = '1.14';
3 4     4   224016 use Mojo::Base 'Mojolicious';
  4         15  
  4         22  
4 4     4   447210 use Mojo::Log;
  4         10  
  4         21  
5 4     4   122 use Mojo::File 'path';
  4         8  
  4         2046  
6              
7             sub startup() {
8 4     4 1 76481 my $s = shift;
9              
10             # plugins
11 4         21 $s->plugin( Config => { default => {docs_root => 'www' }} );
12 4 100       6584 $s->plugin( Config => { file => 'cfg/app.cfg' } )
13             if (-e $s->home->rel_file('cfg/app.cfg'));
14              
15             # log
16 4 50       7379 unless ( $s->app->mode eq 'development' ) {
17 0 0       0 if ( $s->config->{log}->{path} ) {
18             my $log = Mojo::Log->new(
19             path => $s->config->{log}->{path},
20 0   0     0 level => $s->config->{log}->{level} || 'warn',
21             );
22 0         0 $s->app->log($log);
23             }
24             }
25              
26             # support for plugins config in Mojolicious < 9.0
27 4 50 33     588 if ( $Mojolicious::VERSION < 9 && ( my $plugins = $s->config->{plugins} ) ) {
28 0 0       0 die qq{Configuration value "plugins" is not an array reference}
29             unless ref $plugins eq 'ARRAY';
30 0         0 for my $plugin (@$plugins) {
31 0 0       0 die qq{Configuration value "plugins" contains an entry }
32             . qq{that is not a hash reference}
33             unless ref $plugin eq 'HASH';
34 0         0 $s->plugin( ( keys %$plugin )[0], ( values %$plugin )[0] );
35             }
36             }
37              
38             # global configurations
39 4         17 my $cfg = $s->config;
40 4         51 $s->secrets( $cfg->{secret} );
41 4         31 $s->sessions->default_expiration( $cfg->{session}->{default_expiration} );
42 4         91 $s->sessions->cookie_name( $cfg->{session}->{name} );
43              
44             # la root dei file statici
45 4         36 my $docs_root = $s->config->{docs_root};
46 4         27 push @{ $s->app->static->paths }, $s->home->rel_file("$docs_root/public");
  4         12  
47              
48             # ridefinisco la root dei template
49 4         400 $s->app->renderer->paths->[0] = $s->home->rel_file($docs_root)->to_string;
50              
51             # add bundled templates
52 4         399 my $templates_bundled = path(__FILE__)->sibling('Leds')->child('resources');
53 4         323 push @{$s->app->renderer->paths}, $templates_bundled->child('templates');
  4         13  
54 4         362 push @{$s->app->static->paths}, $templates_bundled->child('public');
  4         15  
55             }
56              
57             1;
58              
59             =pod
60              
61             =head1 NAME
62              
63             Mojo::Leds - Leds aka Light Environment (emi) for Development System based on Mojolicious
64              
65             =for html

66            
67             github workflow tests
68            
69             Top language:
70             github last commit
71            

72              
73             =head1 VERSION
74              
75             version 1.14
76              
77             =head1 SYNOPSIS
78              
79             =head1 DESCRIPTION
80              
81             Mojo::Leds is a L app to use a filesystem similiar to classical web site
82              
83             =encoding UTF-8
84              
85             =head1 DIFFERENCES WITH MOJOLICIOUS
86              
87             Mojolicious applications use a filesystem structure closer to a CPAN distribution
88             which is not (IMHO) intuitive.
89              
90             This is a classical Mojolicios applications
91              
92             myapp # Application directory
93             |- script # Script directory
94             | +- my_app # Application script
95             |- lib # Library directory
96             | |- MyApp.pm # Application class
97             | +- MyApp # Application namespace
98             | +- Controller # Controller namespace
99             | +- Example.pm # Controller class
100             |- public # Static file directory (served automatically)
101             | |- index.html # Static HTML file
102             | +- css # Static CSS file
103             | +- example # Static CSS for "Example" controller
104             | +- welcome.css # Static CSS for "welcome" action
105             | |- js # Static JS file
106             | +- example # Static js for "Example" controller
107             | +- welcome.js # Static js for "welcome" action
108             +- templates # Template directory
109             |- layouts # Template directory for layouts
110             | +- default.html.ep # Layout template
111             +- example # Template directory for "Example" controller
112             +- welcome.html.ep # Template for "welcome" action
113              
114             And, as you can see, the "page" welcome has its controller in
115             C, the html code in C,
116             the CSS code in C and its JS code in
117             C.
118              
119             In Mojo::Leds this structure is quite different
120              
121             myapp # Application directory
122             |- cfg # Config directory
123             +- app.cfg # App config file
124             |- script # Script directory
125             | +- my_app # Application script
126             |- lib # Library directory
127             | +- MyApp.pm # Application class
128             |- www # DocumentRoot :-)
129             |- public # Static files directory (served automatically)
130             | |- index.html # Static Home page HTML
131             | |- css # Static CSS file
132             | + app.css # Global Static CSS file
133             | +- js # Static JS file
134             | + app.js # Global Static JS file
135             |- layouts
136             | +- default.html.ep # Layout template
137             +- welcome # Welcome page: directory
138             |- index.pm # Welcome page: controller
139             |- index.html.ep # Welcome page: template
140             |- index.css # Welcome page: CSS file
141             +- index.js # Welcome page: JS file
142              
143             and here, controller, html code, css and js are all inside C directory.
144              
145             =head1 BUGS/CONTRIBUTING
146              
147             Please report any bugs through the web interface at L
148              
149             If you want to contribute changes or otherwise involve yourself in development, feel free to fork the Git repository from
150             L.
151              
152             =head1 SUPPORT
153              
154             You can find this documentation with the perldoc command too.
155              
156             perldoc Mojo::Leds
157              
158             =head1 AUTHOR
159              
160             Emiliano Bruni
161              
162             =head1 COPYRIGHT AND LICENSE
163              
164             This software is copyright (c) 2022 by Emiliano Bruni.
165              
166             This is free software; you can redistribute it and/or modify it under
167             the same terms as the Perl 5 programming language system itself.
168              
169             =cut
170              
171             __END__