| 1 |
package Dancer2; |
| 2 |
$Dancer2::VERSION = '2.2.2'; |
| 3 |
# ABSTRACT: Lightweight yet powerful web application framework |
| 4 |
|
| 5 |
use 5.12.0; |
| 6 |
use strict; |
| 7 |
use warnings; |
| 8 |
use List::Util 'first'; |
| 9 |
use Module::Runtime 'use_module'; |
| 10 |
use Import::Into; |
| 11 |
use Dancer2::Core; |
| 12 |
use Dancer2::Core::App; |
| 13 |
use Dancer2::Core::Runner; |
| 14 |
|
| 15 |
our $AUTHORITY = 'SUKRIA'; |
| 16 |
|
| 17 |
sub VERSION { shift->SUPER::VERSION(@_) || '0.000000_000' } |
| 18 |
|
| 19 |
our $runner; |
| 20 |
|
| 21 |
sub runner {$runner} |
| 22 |
sub psgi_app { shift->runner->psgi_app(@_) } |
| 23 |
|
| 24 |
sub 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 |
|
| 97 |
sub _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 |
|
| 117 |
1; |
| 118 |
|
| 119 |
__END__ |
| 120 |
|
| 121 |
=pod |
| 122 |
|
| 123 |
=encoding UTF-8 |
| 124 |
|
| 125 |
=head1 NAME |
| 126 |
|
| 127 |
Dancer2 - Lightweight yet powerful web application framework |
| 128 |
|
| 129 |
=head1 VERSION |
| 130 |
|
| 131 |
version 2.2.2 |
| 132 |
|
| 133 |
=head1 DESCRIPTION |
| 134 |
|
| 135 |
(If you're looking for the L<dancer2> command documentation via CLI, try |
| 136 |
C<perldoc -F $(which dancer2)>.) |
| 137 |
|
| 138 |
Dancer2 is the new generation of L<Dancer>, the lightweight web framework for |
| 139 |
Perl. Dancer2 is a complete rewrite based on L<Moo>. |
| 140 |
|
| 141 |
Dancer2 can optionally use XS modules for speed, but at its core remains |
| 142 |
fatpackable (via L<App::FatPacker>), enabling you to easily deploy Dancer2 |
| 143 |
applications on hosts that do not support custom CPAN modules. |
| 144 |
|
| 145 |
Creating web applications with Dancer2 is easy and fun: |
| 146 |
|
| 147 |
#!/usr/bin/env perl |
| 148 |
|
| 149 |
package HelloWorld; |
| 150 |
use Dancer2; |
| 151 |
|
| 152 |
get '/' => sub { |
| 153 |
return "Hello, world!"; |
| 154 |
}; |
| 155 |
|
| 156 |
true; |
| 157 |
|
| 158 |
HelloWorld->to_app; |
| 159 |
|
| 160 |
This is the main module for the Dancer2 distribution. It contains logic for |
| 161 |
creating a new Dancer2 application. |
| 162 |
|
| 163 |
=head2 Documentation Index |
| 164 |
|
| 165 |
You have questions. We have answers. |
| 166 |
|
| 167 |
=over 4 |
| 168 |
|
| 169 |
=item * Dancer2 Tutorial |
| 170 |
|
| 171 |
Want to learn by example? The L<Dancer2::Manual::Tutorial> will take you from |
| 172 |
installation to a working application. |
| 173 |
|
| 174 |
item * Quick Start |
| 175 |
|
| 176 |
Want to get going faster? L<Quick Start|Dancer2::Manual::QuickStart> will help you install Dancer2 |
| 177 |
and bootstrap a new application quickly. |
| 178 |
|
| 179 |
=item * Dancer2 Manual |
| 180 |
|
| 181 |
Want to gain understanding of Dancer2 so you can use it best? The |
| 182 |
L<Dancer2::Manual> is a comprehensive guide to the framework. |
| 183 |
|
| 184 |
=item * Dancer2 Keywords |
| 185 |
|
| 186 |
Looking for list of all the keywords? The L<DSL guide|Dancer2::Manual::Keywords> |
| 187 |
documents the entire Dancer2 DSL. |
| 188 |
|
| 189 |
=item * Dancer2 Config |
| 190 |
|
| 191 |
Need to fine tune your application? The L<configuration guide|Dancer2::Manual::Config> |
| 192 |
is the complete reference to all configuration options. |
| 193 |
|
| 194 |
=item * Dancer2 Deployment |
| 195 |
|
| 196 |
Ready to get your application off the ground? L<Deploying Dancer2 applications|Dancer2::Manual::Deployment> |
| 197 |
helps you deploy your application to a real-world host. |
| 198 |
|
| 199 |
=item * Dancer2 Cookbook |
| 200 |
|
| 201 |
How do I...? Our L<cookbook|Dancer2::Manual::Cookbook> comes with various recipes |
| 202 |
in many tasty flavors! |
| 203 |
|
| 204 |
=item * Dancer2 Plugins |
| 205 |
|
| 206 |
Looking for add-on functionality for your application? The L<plugin guide|Dancer2::Manual::Plugins> |
| 207 |
contains our curated list of recommended plugins. |
| 208 |
|
| 209 |
For information on how to author a plugin, see L<the plugin author's guide|Dancer2::Plugin/Writing the plugin>. |
| 210 |
|
| 211 |
=item * Dancer2 Migration guide |
| 212 |
|
| 213 |
Starting from Dancer 1? Jump over to the L<migration guide|Dancer2::Manual::Migration> |
| 214 |
to learn how to make the smoothest transition to Dancer2. |
| 215 |
|
| 216 |
=back |
| 217 |
|
| 218 |
=head3 Other Documentation |
| 219 |
|
| 220 |
=over |
| 221 |
|
| 222 |
=item * Core and Community Policy, and Standards of Conduct |
| 223 |
|
| 224 |
The L<Dancer core and community policy, and standards of conduct|Dancer2::Policy> defines |
| 225 |
what constitutes acceptable behavior in our community, what behavior is considered |
| 226 |
abusive and unacceptable, and what steps will be taken to remediate inappropriate |
| 227 |
and abusive behavior. By participating in any public forum for Dancer or its |
| 228 |
community, you are agreeing to the terms of this policy. |
| 229 |
|
| 230 |
=item * GitHub Wiki |
| 231 |
|
| 232 |
Our L<GitHub wiki|https://github.com/PerlDancer/Dancer2/wiki> has community-contributed |
| 233 |
documentation, as well as other information that doesn't quite fit within |
| 234 |
this manual. |
| 235 |
|
| 236 |
=item * Contributing |
| 237 |
|
| 238 |
The L<contribution guidelines|https://github.com/PerlDancer/Dancer2/blob/master/Contributing.md> describe |
| 239 |
how to set up your development environment to contribute to the development of Dancer2, |
| 240 |
Dancer2's Git workflow, submission guidelines, and various coding standards. |
| 241 |
|
| 242 |
=item * Deprecation Policy |
| 243 |
|
| 244 |
The L<deprecation policy|Dancer2::DeprecationPolicy> defines the process for removing old, |
| 245 |
broken, unused, or outdated code from the Dancer2 codebase. This policy is critical |
| 246 |
for guiding and shaping future development of Dancer2. |
| 247 |
|
| 248 |
=back |
| 249 |
|
| 250 |
=head1 SECURITY REPORTS |
| 251 |
|
| 252 |
If you need to report a security vulnerability in Dancer2, send all pertinent |
| 253 |
information to L<[email protected]|mailto:[email protected]>, or report it |
| 254 |
via the GitHub security tool. These reports will be addressed in the earliest possible |
| 255 |
timeframe. |
| 256 |
|
| 257 |
=head1 SUPPORT |
| 258 |
|
| 259 |
You are welcome to join our mailing list. |
| 260 |
For subscription information, mail address and archives see |
| 261 |
L<http://lists.preshweb.co.uk/mailman/listinfo/dancer-users>. |
| 262 |
|
| 263 |
We are also on IRC: #dancer on irc.perl.org. |
| 264 |
|
| 265 |
=head1 AUTHORS |
| 266 |
|
| 267 |
=head2 CORE DEVELOPERS |
| 268 |
|
| 269 |
Alberto Simões |
| 270 |
Alexis Sukrieh |
| 271 |
D Ruth Holloway (GeekRuthie) |
| 272 |
Damien Krotkine |
| 273 |
David Precious |
| 274 |
Franck Cuny |
| 275 |
Jason A. Crome |
| 276 |
Mickey Nasriachi |
| 277 |
Peter Mottram (SysPete) |
| 278 |
Russell Jenkins |
| 279 |
Sawyer X |
| 280 |
Stefan Hornburg (Racke) |
| 281 |
Yanick Champoux |
| 282 |
|
| 283 |
=head2 CORE DEVELOPERS EMERITUS |
| 284 |
|
| 285 |
David Golden |
| 286 |
Steven Humphrey |
| 287 |
|
| 288 |
=head2 CONTRIBUTORS |
| 289 |
|
| 290 |
A. Sinan Unur |
| 291 |
Abdullah Diab |
| 292 |
Achyut Kumar Panda |
| 293 |
Ahmad M. Zawawi |
| 294 |
Alex Beamish |
| 295 |
Alexander Karelas |
| 296 |
Alexander Pankoff |
| 297 |
Alexandr Ciornii |
| 298 |
Andrew Beverley |
| 299 |
Andrew Grangaard |
| 300 |
Andrew Inishev |
| 301 |
Andrew Solomon |
| 302 |
Andy Jack |
| 303 |
Anton Lundin |
| 304 |
Ashvini V |
| 305 |
B10m |
| 306 |
Bas Bloemsaat |
| 307 |
baynes |
| 308 |
Ben Hutton |
| 309 |
Ben Kaufman |
| 310 |
biafra |
| 311 |
Blabos de Blebe |
| 312 |
Breno G. de Oliveira |
| 313 |
cdmalon |
| 314 |
Celogeek |
| 315 |
Cesare Gargano |
| 316 |
Charlie Gonzalez |
| 317 |
chenchen000 |
| 318 |
Chi Trinh |
| 319 |
Christian Walde |
| 320 |
Christopher White |
| 321 |
cloveistaken |
| 322 |
Colin Kuskie |
| 323 |
cym0n |
| 324 |
Dale Gallagher |
| 325 |
Dan Book (Grinnz) |
| 326 |
Daniel Böhmer |
| 327 |
Daniel Muey |
| 328 |
Daniel Perrett |
| 329 |
Dave Jacoby |
| 330 |
Dave Webb |
| 331 |
David (sbts) |
| 332 |
David Steinbrunner |
| 333 |
David Zurborg |
| 334 |
Davs |
| 335 |
Deirdre Moran |
| 336 |
Dennis Lichtenthäler |
| 337 |
Dinis Rebolo |
| 338 |
dtcyganov |
| 339 |
Elliot Holden |
| 340 |
Emil Perhinschi |
| 341 |
Erik Smit |
| 342 |
Fayland Lam |
| 343 |
ferki |
| 344 |
Gabor Szabo |
| 345 |
GeekRuthie |
| 346 |
geistteufel |
| 347 |
Gideon D'souza |
| 348 |
Gil Magno |
| 349 |
Glenn Fowler |
| 350 |
Graham Knop |
| 351 |
Gregor Herrmann |
| 352 |
Grzegorz Rożniecki |
| 353 |
Hobbestigrou |
| 354 |
Hunter McMillen |
| 355 |
ice-lenor |
| 356 |
icyavocado |
| 357 |
Ivan Bessarabov |
| 358 |
Ivan Kruglov |
| 359 |
JaHIY |
| 360 |
Jakob Voss |
| 361 |
James Aitken |
| 362 |
James Raspass |
| 363 |
James McCoy |
| 364 |
Jason Lewis |
| 365 |
Javier Rojas |
| 366 |
Jean Stebens |
| 367 |
Jens Rehsack |
| 368 |
Joel Berger |
| 369 |
Johannes Piehler |
| 370 |
Jonathan Cast |
| 371 |
Jonathan Scott Duff |
| 372 |
Joseph Frazer |
| 373 |
Julien Fiegehenn (simbabque) |
| 374 |
Julio Fraire |
| 375 |
Kaitlyn Parkhurst (SYMKAT) |
| 376 |
Karen Etheridge |
| 377 |
kbeyazli |
| 378 |
Keith Broughton |
| 379 |
lbeesley |
| 380 |
Lennart Hengstmengel |
| 381 |
Ludovic Tolhurst-Cleaver |
| 382 |
Mario Zieschang |
| 383 |
Mark A. Stratman |
| 384 |
Marketa Wachtlova |
| 385 |
Masaaki Saito |
| 386 |
Mateu X Hunter |
| 387 |
Matt Phillips |
| 388 |
Matt S Trout |
| 389 |
mauke |
| 390 |
Maurice |
| 391 |
MaxPerl |
| 392 |
Ma_Sys.ma |
| 393 |
Menno Blom |
| 394 |
Michael Kröll |
| 395 |
Michał Wojciechowski |
| 396 |
Mike Katasonov |
| 397 |
Mike Weisenborn |
| 398 |
Mikko Koivunalho |
| 399 |
Mohammad S Anwar |
| 400 |
mokko |
| 401 |
Nick Tonkin |
| 402 |
Nigel Gregoire |
| 403 |
Nikita K |
| 404 |
Nova Patch |
| 405 |
Nuno Carvalho |
| 406 |
Olaf Alders |
| 407 |
Olivier Mengué |
| 408 |
Omar M. Othman |
| 409 |
pants |
| 410 |
Patrick Zimmermann |
| 411 |
Pau Amma |
| 412 |
Paul Clements |
| 413 |
Paul Cochrane |
| 414 |
Paul Williams |
| 415 |
Pedro Bruno |
| 416 |
Pedro Melo |
| 417 |
Philippe Bricout |
| 418 |
Ricardo Signes |
| 419 |
Rick Yakubowski |
| 420 |
Ruben Amortegui |
| 421 |
Sakshee Vijay (sakshee3) |
| 422 |
Sam Kington |
| 423 |
Samit Badle |
| 424 |
Sebastien Deseille (sdeseille) |
| 425 |
Sergiy Borodych |
| 426 |
Shlomi Fish |
| 427 |
Slava Goltser |
| 428 |
Snigdha |
| 429 |
Sorin Pop |
| 430 |
Steve Bertrand |
| 431 |
Steve Dondley |
| 432 |
Steven Humphrey |
| 433 |
Tatsuhiko Miyagawa |
| 434 |
Timothy Alexis Vass |
| 435 |
Tina Müller |
| 436 |
Tom Hukins |
| 437 |
Upasana Shukla |
| 438 |
Utkarsh Gupta |
| 439 |
Vernon Lyon |
| 440 |
Victor Adam |
| 441 |
Vince Willems |
| 442 |
Vincent Bachelier |
| 443 |
xenu |
| 444 |
Yves Orton |
| 445 |
|
| 446 |
=head1 AUTHOR |
| 447 |
|
| 448 |
Dancer Core Developers |
| 449 |
|
| 450 |
=head1 COPYRIGHT AND LICENSE |
| 451 |
|
| 452 |
This software is copyright (c) 2026 by Alexis Sukrieh. |
| 453 |
|
| 454 |
This is free software; you can redistribute it and/or modify it under |
| 455 |
the same terms as the Perl 5 programming language system itself. |
| 456 |
|
| 457 |
=cut |