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