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