File Coverage

blib/lib/Dancer2.pm
Criterion Covered Total %
statement 77 77 100.0
branch 13 14 92.8
condition 9 13 69.2
subroutine 19 19 100.0
pod 1 3 33.3
total 119 126 94.4


line stmt bran cond sub pod time code
1             package Dancer2;
2             $Dancer2::VERSION = '0.400001';
3             # ABSTRACT: Lightweight yet powerful web application framework
4              
5 142     148   10150882 use 5.12.0;
  142         1218  
6 142     142   759 use strict;
  142         279  
  142         2948  
7 142     142   704 use warnings;
  142         332  
  142         4395  
8 142     142   2548 use List::Util 'first';
  142         368  
  142         16193  
9 142     142   57690 use Module::Runtime 'use_module';
  142         200609  
  142         930  
10 142     142   65669 use Import::Into;
  142         64223  
  142         4457  
11 142     142   47109 use Dancer2::Core;
  142         341  
  142         3764  
12 142     142   81712 use Dancer2::Core::App;
  142         575  
  142         5898  
13 142     142   70713 use Dancer2::Core::Runner;
  142         619  
  142         5258  
14 142     142   1098 use Dancer2::FileUtils;
  142         335  
  142         81519  
15              
16             our $AUTHORITY = 'SUKRIA';
17              
18 839 50   839 0 40107 sub VERSION { shift->SUPER::VERSION(@_) || '0.000000_000' }
19              
20             our $runner;
21              
22 3363     3363 1 108043 sub runner {$runner}
23 30     30 0 34683 sub psgi_app { shift->runner->psgi_app(@_) }
24              
25             sub import {
26 213     213   53611 my ($class, @args) = @_;
27 213         894 my ($caller, $script) = caller;
28              
29 213         528 my @final_args;
30             my $clean_import;
31 213         608 foreach my $arg (@args) {
32              
33             # ignore, no longer necessary
34             # in the future these will warn as deprecated
35 39 100       179 grep +($arg eq $_), qw<:script :syntax :tests>
36             and next;
37              
38 36 100       130 if ($arg eq ':nopragmas') {
39 1         2 $clean_import++;
40 1         2 next;
41             }
42              
43 35 100       150 if (substr($arg, 0, 1) eq '!') {
44 9         33 push @final_args, $arg, 1;
45             }
46             else {
47 26         65 push @final_args, $arg;
48             }
49             }
50              
51             $clean_import
52             or $_->import::into($caller)
53 213   66     2246 for qw<strict warnings utf8>;
54              
55 213 100       198143 scalar @final_args % 2
56             and die q{parameters must be key/value pairs or '!keyword'};
57              
58 211         666 my %final_args = @final_args;
59              
60 211         528 my $appname = delete $final_args{appname};
61 211   66     1502 $appname ||= $caller;
62              
63             # never instantiated the runner, should do it now
64 211 100       791 if (not defined $runner) {
65 136         951 $runner = Dancer2::Core::Runner->new();
66             }
67              
68             # Search through registered apps, creating a new app object
69             # if we do not find one with the same name.
70 211         516 my $app;
71 211     189   1028 ($app) = first { $_->name eq $appname } @{$runner->apps};
  189         611  
  211         1602  
72              
73 211 100       1204 if (!$app) {
74              
75             # populating with the server's postponed hooks in advance
76             $app = Dancer2::Core::App->new(
77             name => $appname,
78             caller => $script,
79             environment => $runner->environment,
80 200   50     4128 postponed_hooks => $runner->postponed_hooks->{$appname} || {},
81             );
82              
83             # register the app within the runner instance
84 199         3802 $runner->register_application($app);
85             }
86              
87 210         1102 _set_import_method_to_caller($caller);
88              
89             # use config dsl class, must extend Dancer2::Core::DSL
90 210   100     1373 my $config_dsl = $app->setting('dsl_class') || 'Dancer2::Core::DSL';
91 210   66     7366 $final_args{dsl} ||= $config_dsl;
92              
93             # load the DSL, defaulting to Dancer2::Core::DSL
94 210         937 my $dsl = use_module($final_args{dsl})->new(app => $app);
95 210         2526 $dsl->export_symbols_to($caller, \%final_args);
96             }
97              
98             sub _set_import_method_to_caller {
99 210     210   594 my ($caller) = @_;
100              
101             my $import = sub {
102 11     11   1221 my ($self, %options) = @_;
103              
104 11         36 my $with = $options{with};
105 11         4102 for my $key (keys %$with) {
106 5         27 $self->dancer_app->setting($key => $with->{$key});
107             }
108 210         1305 };
109              
110             {
111             ## no critic
112 142     142   1196 no strict 'refs';
  142         360  
  142         6091  
  210         487  
113 142     142   985 no warnings 'redefine';
  142         361  
  142         12081  
114 210         431 *{"${caller}::import"} = $import;
  210         1761  
115             }
116             }
117              
118             1;
119              
120             __END__
121              
122             =pod
123              
124             =encoding UTF-8
125              
126             =head1 NAME
127              
128             Dancer2 - Lightweight yet powerful web application framework
129              
130             =head1 VERSION
131              
132             version 0.400001
133              
134             =head1 DESCRIPTION
135              
136             Dancer2 is the new generation of L<Dancer>, the lightweight web-framework for
137             Perl. Dancer2 is a complete rewrite based on L<Moo>.
138              
139             Dancer2 can optionally use XS modules for speed, but at its core remains
140             fatpackable (packable by L<App::FatPacker>) so you could easily deploy Dancer2
141             applications on hosts that do not support custom CPAN modules.
142              
143             Dancer2 is easy and fun:
144              
145             use Dancer2;
146             get '/' => sub { "Hello World" };
147             dance;
148              
149             This is the main module for the Dancer2 distribution. It contains logic for
150             creating a new Dancer2 application.
151              
152             =head2 Documentation Index
153              
154             Documentation on Dancer2 is split into several sections. Below is a
155             complete outline on where to go for help.
156              
157             =over 4
158              
159             =item * Dancer2 Tutorial
160              
161             If you are new to the Dancer approach, you should start by reading
162             our L<Dancer2::Tutorial>.
163              
164             =item * Dancer2 Manual
165              
166             L<Dancer2::Manual> is the reference for Dancer2. Here you will find
167             information on the concepts of Dancer2 application development and
168             a comprehensive reference to the Dancer2 domain specific
169             language.
170              
171             =item * Dancer2 Keywords
172              
173             The keywords for Dancer2 can be found under L<DSL Keywords|Dancer2::Manual/DSL KEYWORDS>.
174              
175             =item * Dancer2 Deployment
176              
177             For configuration examples of different deployment solutions involving
178             Dancer2 and Plack, refer to L<Dancer2::Manual::Deployment>.
179              
180             =item * Dancer2 Cookbook
181              
182             Specific examples of code for real-life problems and some 'tricks' for
183             applications in Dancer can be found in L<Dancer2::Cookbook>
184              
185             =item * Dancer2 Config
186              
187             For configuration file details refer to L<Dancer2::Config>. It is a
188             complete list of all configuration options.
189              
190             =item * Dancer2 Plugins
191              
192             Refer to L<Dancer2::Plugins> for a partial list of available Dancer2
193             plugins. Note that although we try to keep this list up to date we
194             expect plugin authors to tell us about new modules.
195              
196             For information on how to author a plugin, see L<Dancer2::Plugin/Writing the plugin>.
197              
198             =item * Dancer2 Migration guide
199              
200             L<Dancer2::Manual::Migration> provides the most up-to-date instruction on
201             how to convert a Dancer (1) based application to Dancer2.
202              
203             =back
204              
205             =head3 Other Documentation
206              
207             =over
208              
209             =item * Git Guide
210              
211             The L<Git guide|GitGuide> describes how to set up your development environment to contribute
212             to the development of Dancer2, Dancer2's Git workflow, submission guidelines, and
213             various coding standards.
214              
215             =item * Deprecation Policy
216              
217             The L<deprecation policy|Dancer2::DeprecationPolicy> defines the process for removing old,
218             broken, unused, or outdated code from the Dancer2 codebase. This policy is critical
219             for guiding and shaping future development of Dancer2.
220              
221             =back
222              
223             =head1 FUNCTIONS
224              
225             =head2 my $runner=runner();
226              
227             Returns the current runner. It is of type L<Dancer2::Core::Runner>.
228              
229             =head1 SECURITY REPORTS
230              
231             If you need to report a security vulnerability in Dancer2, send all pertinent
232             information to L<mailto:dancer-security@dancer.pm>. These matters are taken
233             extremely seriously, and will be addressed in the earliest timeframe possible.
234              
235             =head1 SUPPORT
236              
237             You are welcome to join our mailing list.
238             For subscription information, mail address and archives see
239             L<http://lists.preshweb.co.uk/mailman/listinfo/dancer-users>.
240              
241             We are also on IRC: #dancer on irc.perl.org.
242              
243             =head1 AUTHORS
244              
245             =head2 CORE DEVELOPERS
246              
247             Alberto Simões
248             Alexis Sukrieh
249             Damien Krotkine
250             David Precious
251             Franck Cuny
252             Jason A. Crome
253             Mickey Nasriachi
254             Peter Mottram (SysPete)
255             Russell Jenkins
256             Sawyer X
257             Stefan Hornburg (Racke)
258             Steven Humphrey
259             Yanick Champoux
260              
261             =head2 CORE DEVELOPERS EMERITUS
262              
263             David Golden
264              
265             =head2 CONTRIBUTORS
266              
267             A. Sinan Unur
268             Abdullah Diab
269             Achyut Kumar Panda
270             Ahmad M. Zawawi
271             Alex Beamish
272             Alexander Karelas
273             Alexander Pankoff
274             Alexandr Ciornii
275             Andrew Beverley
276             Andrew Grangaard
277             Andrew Inishev
278             Andrew Solomon
279             Andy Jack
280             Ashvini V
281             B10m
282             Bas Bloemsaat
283             baynes
284             Ben Hutton
285             Ben Kaufman
286             biafra
287             Blabos de Blebe
288             Breno G. de Oliveira
289             cdmalon
290             Celogeek
291             Cesare Gargano
292             Charlie Gonzalez
293             chenchen000
294             Chi Trinh
295             Christian Walde
296             Christopher White
297             cloveistaken
298             Colin Kuskie
299             cym0n
300             Dale Gallagher
301             Dan Book (Grinnz)
302             Daniel Böhmer
303             Daniel Muey
304             Daniel Perrett
305             Dave Jacoby
306             Dave Webb
307             David (sbts)
308             David Steinbrunner
309             David Zurborg
310             Davs
311             Deirdre Moran
312             Dennis Lichtenthäler
313             Dinis Rebolo
314             dtcyganov
315             Elliot Holden
316             Erik Smit
317             Fayland Lam
318             ferki
319             Gabor Szabo
320             geistteufel
321             Gideon D'souza
322             Gil Magno
323             Glenn Fowler
324             Graham Knop
325             Gregor Herrmann
326             Grzegorz Rożniecki
327             Hobbestigrou
328             Hunter McMillen
329             ice-lenor
330             Ivan Bessarabov
331             Ivan Kruglov
332             JaHIY
333             Jakob Voss
334             James Aitken
335             James Raspass
336             James McCoy
337             Jason Lewis
338             Javier Rojas
339             Jean Stebens
340             Jens Rehsack
341             Joel Berger
342             Johannes Piehler
343             Jonathan Cast
344             Jonathan Scott Duff
345             Joseph Frazer
346             Julien Fiegehenn (simbabque)
347             Julio Fraire
348             Kaitlyn Parkhurst (SYMKAT)
349             kbeyazli
350             Keith Broughton
351             lbeesley
352             Lennart Hengstmengel
353             Ludovic Tolhurst-Cleaver
354             Mario Zieschang
355             Mark A. Stratman
356             Marketa Wachtlova
357             Masaaki Saito
358             Mateu X Hunter
359             Matt Phillips
360             Matt S Trout
361             Maurice
362             MaxPerl
363             Ma_Sys.ma
364             Menno Blom
365             Michael Kröll
366             Michał Wojciechowski
367             Mike Katasonov
368             Mohammad S Anwar
369             mokko
370             Nick Patch
371             Nick Tonkin
372             Nigel Gregoire
373             Nikita K
374             Nuno Carvalho
375             Olaf Alders
376             Olivier Mengué
377             Omar M. Othman
378             pants
379             Patrick Zimmermann
380             Pau Amma
381             Paul Clements
382             Paul Cochrane
383             Paul Williams
384             Pedro Bruno
385             Pedro Melo
386             Philippe Bricout
387             Ricardo Signes
388             Rick Yakubowski
389             Ruben Amortegui
390             Sakshee Vijay (sakshee3)
391             Sam Kington
392             Samit Badle
393             Sebastien Deseille (sdeseille)
394             Sergiy Borodych
395             Shlomi Fish
396             Slava Goltser
397             Snigdha
398             Steve Bertrand
399             Steve Dondley
400             Tatsuhiko Miyagawa
401             Timothy Alexis Vass
402             Tina Müller
403             Tom Hukins
404             Upasana Shukla
405             Utkarsh Gupta
406             Vernon Lyon
407             Victor Adam
408             Vince Willems
409             Vincent Bachelier
410             xenu
411             Yves Orton
412              
413             =head1 AUTHOR
414              
415             Dancer Core Developers
416              
417             =head1 COPYRIGHT AND LICENSE
418              
419             This software is copyright (c) 2023 by Alexis Sukrieh.
420              
421             This is free software; you can redistribute it and/or modify it under
422             the same terms as the Perl 5 programming language system itself.
423              
424             =cut