Yancy.pm

filter: Statementstmt 81.2% 26 / 32 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 80.4% 37 / 46 CC 6 SCAR 13.3
CC
6
Cov
78%
startup
6.2
__ANON__
2.0
BEGIN
1.0
CRAP 3.8
« Yancy/Command/backend/copy.pm ↑ Summary Yancy/Plugin/Auth.pm »
1 package Yancy;
2 22 our $VERSION = '1.088';
3 # ABSTRACT: The Best Web Framework Deserves the Best CMS
4  
5 # "Mr. Fry: Son, your name is Yancy, just like me and my grandfather and
6 # so on. All the way back to minuteman Yancy Fry, who blasted commies in
7 # the American Revolution."
8  
9 #pod =encoding utf8
10 #pod
11 #pod =head1 DESCRIPTION
12 #pod
13 #pod Yancy is a simple content management system (CMS) for the L<Mojolicious> web framework.
14 #pod
15 #pod =begin html
16 #pod
17 #pod <div style="display: flex">
18 #pod <div style="margin: 3px; flex: 1 1 50%">
19 #pod <img alt="Screenshot of list of Futurama characters" src="https://raw.github.com/preaction/Yancy/master/eg/doc-site/public/screenshot.png?raw=true" style="max-width: 100%" width="600">
20 #pod </div>
21 #pod <div style="margin: 3px; flex: 1 1 50%">
22 #pod <img alt="Screenshot of editing form for a person" src="https://raw.github.com/preaction/Yancy/master/eg/doc-site/public/screenshot-edit.png?raw=true" style="max-width: 100%" width="600">
23 #pod </div>
24 #pod </div>
25 #pod
26 #pod =end html
27 #pod
28 #pod Get started with L<the Yancy documentation|Yancy::Guides>!
29 #pod
30 #pod This file documents the application base class. You can use this class directly
31 #pod via the C<yancy> command, or you can extend this class to build your own app.
32 #pod
33 #pod =head1 Starting Your Own Yancy Application
34 #pod
35 #pod If you have an existing L<Mojolicious> application you want to add Yancy
36 #pod to, see L<Mojolicious::Plugin::Yancy>.
37 #pod
38 #pod The base Yancy class exists to provide a way to rapidly prototype a data-driven
39 #pod web application. Apps that inherit from Yancy get these features out-of-the-box:
40 #pod
41 #pod =over
42 #pod
43 #pod =item * The Yancy CMS (L<Mojolicious::Plugin::Yancy>)
44 #pod
45 #pod =item * Database editor (L<Yancy::Plugin::Editor>)
46 #pod
47 #pod =item * User logins (L<Yancy::Plugin::Auth>)
48 #pod
49 #pod =item * Role-based access controls (L<Yancy::Plugin::Roles>)
50 #pod
51 #pod =back
52 #pod
53 #pod If you're familiar with developing Mojolicious applications, you can start
54 #pod from the app skeleton at L<https://github.com/preaction/Yancy/tree/master/eg/skeleton>.
55 #pod
56 #pod =for comment XXX: Create `yancy generate app` and `yancy generate lite-app` commands
57 #pod
58 #pod To begin writing a new application from scratch, create a C<lib>
59 #pod directory and add a C<MyApp.pm> file that extends the C<Yancy> class:
60 #pod
61 #pod package MyApp;
62 #pod use Mojo::Base 'Yancy', -signatures;
63 #pod
64 #pod As in any other L<Mojolicious> app, add your routes, plugins, and other setup to
65 #pod the C<startup> method. Don't forget to call Yancy's L</startup> method!
66 #pod
67 #pod sub startup( $self ) {
68 #pod $self->SUPER::startup;
69 #pod # ... Add your routes and other setup here
70 #pod }
71 #pod
72 #pod Next, create a configuration file named C<my_app.conf> to connect to your database:
73 #pod
74 #pod {
75 #pod backend => 'sqlite:my_app.db',
76 #pod }
77 #pod
78 #pod Last, create a L<simple application script|https://docs.mojolicious.org/Mojolicious/Guides/Growing#Simplified-application-script>
79 #pod named C<script/my_app> to start your application:
80 #pod
81 #pod #!/usr/bin/env perl
82 #pod
83 #pod use Mojo::Base -strict;
84 #pod use lib qw(lib);
85 #pod use Mojolicious::Commands;
86 #pod
87 #pod # Start command line interface for application
88 #pod Mojolicious::Commands->start_app('MyApp');
89 #pod
90 #pod Now you can run C<./script/my_app daemon> to start your app!
91 #pod
92 #pod To make developing your app easy and fun, make sure you're familiar with
93 #pod these guides:
94 #pod
95 #pod =over
96 #pod
97 #pod =item L<The Mojolicious tutorial and guides|https://docs.mojolicious.org>
98 #pod
99 #pod =item L<The Yancy tutorial|Yancy::Guides::Tutorial>
100 #pod
101 #pod =item L<The Yancy guides|Yancy::Guides>
102 #pod
103 #pod =back
104 #pod
105 #pod =head1 BUNDLED PROJECTS
106 #pod
107 #pod This project bundles some other projects with the following licenses:
108 #pod
109 #pod =over
110 #pod
111 #pod =item * L<jQuery|http://jquery.com> (version 3.2.1) Copyright JS Foundation and other contributors (MIT License)
112 #pod
113 #pod =item * L<Bootstrap|http://getbootstrap.com> (version 4.3.1) Copyright 2011-2019 the Bootstrap Authors and Twitter, Inc. (MIT License)
114 #pod
115 #pod =item * L<Popper.js|https://popper.js.org> (version 1.13.0) Copyright 2017 Federico Zivolo (MIT License)
116 #pod
117 #pod =item * L<FontAwesome|http://fontawesome.io> (version 4.7.0) Copyright Dave Gandy (SIL OFL 1.1 and MIT License)
118 #pod
119 #pod =item * L<Vue.js|http://vuejs.org> (version 2.5.3) Copyright 2013-2018, Yuxi (Evan) You (MIT License)
120 #pod
121 #pod =item * L<marked|https://github.com/chjj/marked> (version 0.3.12) Copyright 2011-2018, Christopher Jeffrey (MIT License)
122 #pod
123 #pod =back
124 #pod
125 #pod The bundled versions of these modules may change. If you rely on these in your own app,
126 #pod be sure to watch the changelog for version updates.
127 #pod
128 #pod =head1 SEE ALSO
129 #pod
130 #pod L<Mojolicious>
131 #pod
132 #pod =cut
133  
134 22 ▶use Mojo::Base 'Mojolicious';
Subroutine BEGIN: called CC=1 SCAR=0.0
135 22 ▶use Mojo::File qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
136 22 ▶use Mojo::Loader qw( data_section );
Subroutine BEGIN: called CC=1 SCAR=0.0
137  
138 # Default home should be the current working directory so that config,
139 # templates, and static files can be found.
140 5 ▶has home => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
141 5 ▶ return !$ENV{MOJO_HOME} ? path : $_[0]->SUPER::home;
Branch: 1 branch
BranchTrueFalseTotal
!$ENV{'MOJO_HOME'} ? : 1 4 5
142 22 };
143  
144 5 ▶sub startup {
Subroutine startup: called CC=5 SCAR=18.2
Pod documented
145 5 my ( $app ) = @_;
146 5 unshift @{$app->plugins->namespaces}, 'Yancy::Plugin';
147  
148 5 ▶ if ( !keys %{ $app->config } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %{$app->config;}) 0 5 5
149 0 $app->plugin( Config => { } );
150 }
151 5 $app->plugin( 'Yancy', $app->config );
152  
153 # XXX: Add default migrations
154 # Set up default auth plugin if no auth found yet
155 1 ▶ if ( !$app->yancy->can( 'auth' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($app->yancy->can("auth")) 1 0 1
156 # Update schema if needed
157 # XXX: Add named migration support to backends. Migration should
158 # trigger a re-read of the schema.
159 1 my ( $backend_type ) = ( lc ref $app->yancy->backend ) =~ m{::([^:]+)$};
160 1 ▶ if ( my $sql = data_section __PACKAGE__, "migrations.yancy_logins.$backend_type.sql" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sql = data_section(__PACKAGE__, "migrations.yancy_logins.$backend_type.sql")) 0 1 1
161 0 my $migrations = (ref $app->yancy->backend->driver->migrations)->new( $backend_type => $app->yancy->backend->driver );
162 0 $migrations->name( 'yancy_logins' )->from_string( $sql )->migrate;
163 0 for my $table ( qw( yancy_logins yancy_login_roles ) ) {
164 0 my $schema = $app->yancy->backend->read_schema( $table );
165 0 $app->yancy->schema( $table => $schema );
166 }
167 }
168  
169 1 $app->plugin( Auth => {
170 schema => 'yancy_logins',
171 username_field => 'login_name',
172 plugins => [
173 [
174 Password => {
175 password_field => 'password',
176 password_digest => { type => 'SHA-1' },
177 },
178 ],
179 ],
180 } );
181  
182 # XXX: Create a "Setup" plugin to initialize an admin login if
183 # no logins exist
184 }
185  
186 1 $app->plugin( Roles => {
187 schema => 'yancy_login_roles',
188 userid_field => 'login_id',
189 role_field => 'role',
190 } );
191  
192 # Add default not_found renderer
193 1 push @{$app->renderer->classes}, 'Yancy';
194 }
195  
196 22 1;
197  
198 =pod
199  
200 =head1 NAME
201  
202 Yancy - The Best Web Framework Deserves the Best CMS
203  
204 =head1 VERSION
205  
206 version 1.088
207  
208 =head1 DESCRIPTION
209  
210 Yancy is a simple content management system (CMS) for the L<Mojolicious> web framework.
211  
212 =encoding utf8
213  
214 =for html <div style="display: flex">
215 <div style="margin: 3px; flex: 1 1 50%">
216 <img alt="Screenshot of list of Futurama characters" src="https://raw.github.com/preaction/Yancy/master/eg/doc-site/public/screenshot.png?raw=true" style="max-width: 100%" width="600">
217 </div>
218 <div style="margin: 3px; flex: 1 1 50%">
219 <img alt="Screenshot of editing form for a person" src="https://raw.github.com/preaction/Yancy/master/eg/doc-site/public/screenshot-edit.png?raw=true" style="max-width: 100%" width="600">
220 </div>
221 </div>
222  
223 Get started with L<the Yancy documentation|Yancy::Guides>!
224  
225 This file documents the application base class. You can use this class directly
226 via the C<yancy> command, or you can extend this class to build your own app.
227  
228 =head1 Starting Your Own Yancy Application
229  
230 If you have an existing L<Mojolicious> application you want to add Yancy
231 to, see L<Mojolicious::Plugin::Yancy>.
232  
233 The base Yancy class exists to provide a way to rapidly prototype a data-driven
234 web application. Apps that inherit from Yancy get these features out-of-the-box:
235  
236 =over
237  
238 =item * The Yancy CMS (L<Mojolicious::Plugin::Yancy>)
239  
240 =item * Database editor (L<Yancy::Plugin::Editor>)
241  
242 =item * User logins (L<Yancy::Plugin::Auth>)
243  
244 =item * Role-based access controls (L<Yancy::Plugin::Roles>)
245  
246 =back
247  
248 If you're familiar with developing Mojolicious applications, you can start
249 from the app skeleton at L<https://github.com/preaction/Yancy/tree/master/eg/skeleton>.
250  
251 =for comment XXX: Create `yancy generate app` and `yancy generate lite-app` commands
252  
253 To begin writing a new application from scratch, create a C<lib>
254 directory and add a C<MyApp.pm> file that extends the C<Yancy> class:
255  
256 package MyApp;
257 use Mojo::Base 'Yancy', -signatures;
258  
259 As in any other L<Mojolicious> app, add your routes, plugins, and other setup to
260 the C<startup> method. Don't forget to call Yancy's L</startup> method!
261  
262 sub startup( $self ) {
263 $self->SUPER::startup;
264 # ... Add your routes and other setup here
265 }
266  
267 Next, create a configuration file named C<my_app.conf> to connect to your database:
268  
269 {
270 backend => 'sqlite:my_app.db',
271 }
272  
273 Last, create a L<simple application script|https://docs.mojolicious.org/Mojolicious/Guides/Growing#Simplified-application-script>
274 named C<script/my_app> to start your application:
275  
276 #!/usr/bin/env perl
277  
278 use Mojo::Base -strict;
279 use lib qw(lib);
280 use Mojolicious::Commands;
281  
282 # Start command line interface for application
283 Mojolicious::Commands->start_app('MyApp');
284  
285 Now you can run C<./script/my_app daemon> to start your app!
286  
287 To make developing your app easy and fun, make sure you're familiar with
288 these guides:
289  
290 =over
291  
292 =item L<The Mojolicious tutorial and guides|https://docs.mojolicious.org>
293  
294 =item L<The Yancy tutorial|Yancy::Guides::Tutorial>
295  
296 =item L<The Yancy guides|Yancy::Guides>
297  
298 =back
299  
300 =head1 BUNDLED PROJECTS
301  
302 This project bundles some other projects with the following licenses:
303  
304 =over
305  
306 =item * L<jQuery|http://jquery.com> (version 3.2.1) Copyright JS Foundation and other contributors (MIT License)
307  
308 =item * L<Bootstrap|http://getbootstrap.com> (version 4.3.1) Copyright 2011-2019 the Bootstrap Authors and Twitter, Inc. (MIT License)
309  
310 =item * L<Popper.js|https://popper.js.org> (version 1.13.0) Copyright 2017 Federico Zivolo (MIT License)
311  
312 =item * L<FontAwesome|http://fontawesome.io> (version 4.7.0) Copyright Dave Gandy (SIL OFL 1.1 and MIT License)
313  
314 =item * L<Vue.js|http://vuejs.org> (version 2.5.3) Copyright 2013-2018, Yuxi (Evan) You (MIT License)
315  
316 =item * L<marked|https://github.com/chjj/marked> (version 0.3.12) Copyright 2011-2018, Christopher Jeffrey (MIT License)
317  
318 =back
319  
320 The bundled versions of these modules may change. If you rely on these in your own app,
321 be sure to watch the changelog for version updates.
322  
323 =head1 SEE ALSO
324  
325 L<Mojolicious>
326  
327 =head1 AUTHOR
328  
329 Doug Bell <preaction@cpan.org>
330  
331 =head1 CONTRIBUTORS
332  
333 =for stopwords Boris Däppen Ed J Erik Johansen flash548 Josh Rabinowitz Mohammad S Anwar Pavel Serikov Rajesh Mallah Roy Storey William Lindley Wojtek Bażant
334  
335 =over 4
336  
337 =item *
338  
339 Boris Däppen <bdaeppen.perl@gmail.com>
340  
341 =item *
342  
343 Ed J <mohawk2@users.noreply.github.com>
344  
345 =item *
346  
347 Erik Johansen <github@uniejo.dk>
348  
349 =item *
350  
351 flash548 <59771551+flash548@users.noreply.github.com>
352  
353 =item *
354  
355 Josh Rabinowitz <joshr@joshr.com>
356  
357 =item *
358  
359 Mohammad S Anwar <mohammad.anwar@yahoo.com>
360  
361 =item *
362  
363 Pavel Serikov <pavelsr@cpan.org>
364  
365 =item *
366  
367 Rajesh Mallah <mallah.rajesh@gmail.com>
368  
369 =item *
370  
371 Roy Storey <kiwiroy@users.noreply.github.com>
372  
373 =item *
374  
375 William Lindley <wlindley@wlindley.com>
376  
377 =item *
378  
379 Wojtek Bażant <wojciech.bazant+ebi@gmail.com>
380  
381 =back
382  
383 =head1 COPYRIGHT AND LICENSE
384  
385 This software is copyright (c) 2021 by Doug Bell.
386  
387 This is free software; you can redistribute it and/or modify it under
388 the same terms as the Perl 5 programming language system itself.
389  
390 =cut
391  
392 __DATA__
« Yancy/Command/backend/copy.pm ↑ Summary Yancy/Plugin/Auth.pm »