/
dancer
executable file
·1496 lines (1305 loc) · 110 KB
/
dancer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
use strict;
use warnings;
use Dancer::Template::Simple;
use File::Basename 'basename', 'dirname';
use File::Path 'mkpath';
use File::Spec::Functions;
use Getopt::Long;
use Pod::Usage;
use Dancer::Renderer;
use LWP::UserAgent;
use constant FILE => 1;
# options
my $help = 0;
my $do_check_dancer_version = 1;
my $name = undef;
my $path = '.';
sub templates($);
sub app_tree($);
sub create_node($;$);
GetOptions(
"h|help" => \$help,
"a|application=s" => \$name,
"p|path=s" => \$path,
"x|no-check" => sub { $do_check_dancer_version = 0 },
"v|version" => \&version,
) or pod2usage( -verbose => 1 );
# main
my $PERL_INTERPRETER = -r '/usr/bin/env' ? '#!/usr/bin/env perl' : "#!$^X";
pod2usage( -verbose => 1 ) if $help;
pod2usage( -verbose => 1 ) if not defined $name;
pod2usage( -verbose => 1 ) unless -d $path && -w $path;
sub version {require Dancer; print 'Dancer ' . $Dancer::VERSION . "\n"; exit 0;}
validate_app_name($name);
my $DO_OVERWRITE_ALL = 0;
my $DANCER_APP_DIR = get_application_path($path, $name);
my $DANCER_SCRIPT = get_script_path($name);
my ($LIB_FILE, $LIB_PATH) = get_lib_path($name);
my $AUTO_RELOAD = eval "require Module::Refresh and require Clone" ? 1 : 0;
require Dancer;
my $DANCER_VERSION = $Dancer::VERSION;
version_check() if $do_check_dancer_version;
safe_mkdir($DANCER_APP_DIR);
create_node( app_tree($name), $DANCER_APP_DIR );
# subs
sub validate_app_name {
my $name = shift;
if ($name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) {
print STDERR "Error: Invalid application name.\n";
print STDERR "Application names must not contain colons,"
." dots or start with a number.\n";
exit;
}
}
sub get_application_path {
my ($path, $app_name) = @_;
catdir($path, _dash_name($app_name));
}
sub get_lib_path {
my $name = shift;
my @lib_path = split('::', $name);
my ($lib_file, $lib_path) = (pop @lib_path) . ".pm";
$lib_path = join('/', @lib_path);
return ($lib_file, $lib_path);
}
sub get_script_path {
_dash_name(shift);
}
sub _dash_name {
my $name = shift;
$name =~ s/\:\:/-/g;
$name;
}
sub create_node($;$) {
my ($node, $root) = @_;
$root ||= '.';
my $manifest_name = catfile($root => 'MANIFEST');
open my $manifest, ">", $manifest_name or die $!;
# create a closure, so we do not need to get $root passed as
# argument on _create_node
my $add_to_manifest = sub {
my $file = shift;
$file =~ s{^$root/?}{};
print $manifest "$file\n";
};
$add_to_manifest->($manifest_name);
_create_node($add_to_manifest, $node, $root);
close $manifest;
}
sub _create_node {
my ($add_to_manifest, $node, $root) = @_;
my $templates = templates($name);
while ( my ($path, $content) = each %$node ) {
$path = catfile($root, $path);
if (ref($content) eq 'HASH') {
safe_mkdir($path);
_create_node($add_to_manifest, $content, $path);
} elsif (ref($content) eq 'CODE') {
# The content is a coderef, which, given the path to the file it
# should create, will do the appropriate thing:
$content->($path);
$add_to_manifest->($path);
} else {
my $file = basename($path);
my $dir = dirname($path);
my $ex = ($file =~ s/^\+//); # look for '+' flag (executable)
my $template = $templates->{$file};
$path = catfile($dir, $file); # rebuild the path without the '+' flag
write_file($path, $template, {appdir => File::Spec->rel2abs($DANCER_APP_DIR)});
chmod 0755, $path if $ex;
$add_to_manifest->($path);
}
}
}
sub app_tree($) {
my ($appname) = @_;
return {
"Makefile.PL" => FILE,
"MANIFEST.SKIP" => FILE,
lib => {
$LIB_PATH => {
$LIB_FILE => FILE,}
},
"bin" => {
"+app.pl" => FILE,
},
"config.yml" => FILE,
"environments" => {
"development.yml" => FILE,
"production.yml" => FILE,
},
"views" => {
"layouts" => {"main.tt" => FILE,},
"index.tt" => FILE,
},
"public" => {
"+dispatch.cgi" => FILE,
"+dispatch.fcgi" => FILE,
"404.html" => FILE,
"500.html" => FILE,
"css" => {
"style.css" => FILE,
"error.css" => FILE,
},
"images" => {
"perldancer-bg.jpg" => \&write_bg,
"perldancer.jpg" => \&write_logo,
},
"javascripts" => {
"jquery.js" => FILE,
},
"favicon.ico" => \&write_favicon,
},
"t" => {
"001_base.t" => FILE,
"002_index_route.t" => FILE,
},
};
}
sub safe_mkdir {
my ($dir) = @_;
if (not -d $dir) {
print "+ $dir\n";
mkpath $dir or die "could not mkpath $dir: $!";
}
else {
print " $dir\n";
}
}
sub write_file {
my ($path, $template, $vars) = @_;
die "no template found for $path" unless defined $template;
$vars->{dancer_version} = $DANCER_VERSION;
# if file already exists, ask for confirmation
if (-f $path && (not $DO_OVERWRITE_ALL)) {
print "! $path exists, overwrite? [N/y/a]: ";
my $res = <STDIN>; chomp($res);
$DO_OVERWRITE_ALL = 1 if $res eq 'a';
return 0 unless ($res eq 'y') or ($res eq 'a');
}
my $fh;
my $content = process_template($template, $vars);
print "+ $path\n";
open $fh, '>', $path or die "unable to open file `$path' for writing: $!";
print $fh $content;
close $fh;
}
sub process_template {
my ($template, $tokens) = @_;
my $engine = Dancer::Template::Simple->new;
$engine->{start_tag} = '[%';
$engine->{stop_tag} = '%]';
return $engine->render(\$template, $tokens);
}
sub write_data_to_file {
my ($data, $path) = @_;
open(my $fh, '>', $path)
or warn "Failed to write file to $path - $!" and return;
binmode($fh);
print {$fh} unpack 'u*', $data;
close $fh;
}
sub send_http_request {
my $url = shift;
my $ua = LWP::UserAgent->new;
$ua->timeout(5);
$ua->env_proxy();
my $response = $ua->get($url);
if ($response->is_success) {
return $response->content;
}
else {
return;
}
}
sub version_check {
my $latest_version = 0;
require Dancer;
my $resp = send_http_request('http://search.cpan.org/api/module/Dancer');
if ($resp) {
if ( $resp =~ /"version" (?:\s+)? \: (?:\s+)? "(\d\.\d+)"/x ) {
$latest_version = $1;
} else {
die "Can't understand search.cpan.org's reply.\n";
}
}
return if $DANCER_VERSION =~ m/_/;
if ($latest_version > $DANCER_VERSION) {
print qq|
The latest stable Dancer release is $latest_version, you are currently using $DANCER_VERSION.
Please check http://search.cpan.org/dist/Dancer/ for updates.
|;
}
}
sub download_file {
my ($path, $url) = @_;
my $resp = send_http_request($url);
if ($resp) {
open my $fh, '>', $path or die "cannot open $path for writing: $!";
print $fh $resp;
close $fh
}
return 1;
}
sub templates($) {
my $appname = shift;
my $appfile = $appname;
my $cleanfiles = $appname;
$appfile =~ s{::}{/}g;
$cleanfiles =~ s{::}{-}g;
return {
'Makefile.PL' =>
"use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => '$appname',
AUTHOR => q{YOUR NAME <youremail\@example.com>},
VERSION_FROM => 'lib/$appfile.pm',
ABSTRACT => 'YOUR APPLICATION ABSTRACT',
(\$ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
: ()),
PL_FILES => {},
PREREQ_PM => {
'Test::More' => 0,
'YAML' => 0,
'Dancer' => [% dancer_version %],
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => '$cleanfiles-*' },
);
",
'index.tt' =>
'
<!--
Credit goes to the Ruby on Rails team for this page
has been heavily based on the default Rails page that is
built with a scaffolded application.
Thanks a lot to them for their work.
See Ruby on Rails if you want a kickass framework in Ruby:
http://www.rubyonrails.org/
-->
<div id="page">
<div id="sidebar">
<ul id="sidebar-items">
<li>
<h3>Join the community</h3>
<ul class="links">
<li><a href="http://perldancer.org/">PerlDancer</a></li>
<li><a href="http://twitter.com/PerlDancer/">Official Twitter</a></li>
<li><a href="http://github.com/sukria/Dancer/">GitHub Community</a></li>
</ul>
</li>
<li>
<h3>Browse the documentation</h3>
<ul class="links">
<li><a
href="http://search.cpan.org/dist/Dancer/lib/Dancer/Introduction.pod">Introduction</a></li>
<li><a href="http://search.cpan.org/dist/Dancer/lib/Dancer/Cookbook.pod">Cookbook</a></li>
<li><a href="http://search.cpan.org/dist/Dancer/lib/Dancer/Deployment.pod">Deployment Guide</a></li>
<li><a
href="http://search.cpan.org/dist/Dancer/lib/Dancer/Tutorial.pod"
title="a tutorial to build a small blog engine with Dancer">Tutorial</a></li>
</ul>
</li>
<li>
<h3>Your application\'s environment</h3>
<ul>
<li>Location: <code>[% appdir %]</code></li>
<li>Template engine: <code><% settings.template %></code></li>
<li>Logger: <code><% settings.logger %></code></li>
<li>Environment: <code><% settings.environment %></code></li>
</ul>
</li>
</ul>
</div>
<div id="content">
<div id="header">
<h1>Perl is dancing</h1>
<h2>You’ve joined the dance floor!</h2>
</div>
<div id="getting-started">
<h1>Getting started</h1>
<h2>Here’s how to get dancing:</h2>
<h3><a href="#" id="about_env_link">About your application\'s environment</a></h3>
<div id="about-content" style="display: none;">
<table>
<tbody>
<tr>
<td>Perl version</td>
<td><tt><% perl_version %></tt></td>
</tr>
<tr>
<td>Dancer version</td>
<td><tt><% dancer_version %></tt></td>
</tr>
<tr>
<td>Backend</td>
<td><tt><% settings.apphandler %></tt></td>
</tr>
<tr>
<td>Appdir</td>
<td><tt>[% appdir %]</tt></td>
</tr>
<tr>
<td>Template engine</td>
<td><tt><% settings.template %></tt></td>
</tr>
<tr>
<td>Logger engine</td>
<td><tt><% settings.logger %></tt></td>
</tr>
<tr>
<td>Running environment</td>
<td><tt><% settings.environment %></tt></td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
$(\'#about_env_link\').click(function() {
$(\'#about-content\').slideToggle(\'fast\', function() {
// ok
});
});
</script>
<ol>
<li>
<h2>Tune your application</h2>
<p>
Your application is configured via a global configuration file,
<tt>config.yml</tt> and an "environment" configuration file,
<tt>environments/development.yml</tt>. Edit those files if you
want to change the settings of your application.
</p>
</li>
<li>
<h2>Add your own routes</h2>
<p>
The default route that displays this page can be removed,
it\'s just here to help you get started. The template used to
generate this content is located in
<code>views/index.tt</code>.
You can add some routes to <tt>lib/'.$LIB_PATH.'/'.$LIB_FILE.'</tt>.
</p>
</li>
<li>
<h2>Enjoy web development again</h2>
<p>
Once you\'ve made your changes, restart your standalone server
(bin/app.pl) and you\'re ready to test your web application.
</p>
</li>
</ol>
</div>
</div>
</div>
',
'main.tt' =>
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=<% settings.charset %>" />
<title>'.$appname.'</title>
<link rel="stylesheet" href="<% request.uri_base %>/css/style.css" />
<!-- Grab Google CDN\'s jQuery. fall back to local if necessary -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">/* <![CDATA[ */
!window.jQuery && document.write(\'<script type="text/javascript" src="<% request.uri_base %>/javascripts/jquery.js"><\/script>\')
/* ]]> */</script>
</head>
<body>
<% content %>
<div id="footer">
Powered by <a href="http://perldancer.org/">Dancer</a> <% dancer_version %>
</div>
</body>
</html>
',
"dispatch.cgi" =>
"$PERL_INTERPRETER
use Dancer ':syntax';
use FindBin '\$RealBin';
use Plack::Runner;
# For some reason Apache SetEnv directives dont propagate
# correctly to the dispatchers, so forcing PSGI and env here
# is safer.
set apphandler => 'PSGI';
set environment => 'production';
my \$psgi = path(\$RealBin, '..', 'bin', 'app.pl');
die \"Unable to read startup script: \$psgi\" unless -r \$psgi;
Plack::Runner->run(\$psgi);
",
"dispatch.fcgi" =>
qq{$PERL_INTERPRETER
use Dancer ':syntax';
use FindBin '\$RealBin';
use Plack::Handler::FCGI;
# For some reason Apache SetEnv directives dont propagate
# correctly to the dispatchers, so forcing PSGI and env here
# is safer.
set apphandler => 'PSGI';
set environment => 'production';
my \$psgi = path(\$RealBin, '..', 'bin', 'app.pl');
my \$app = do(\$psgi);
die "Unable to read startup script: \$@" if \$@;
my \$server = Plack::Handler::FCGI->new(nproc => 5, detach => 1);
\$server->run(\$app);
},
"app.pl" =>
"$PERL_INTERPRETER
use Dancer;
use $appname;
dance;
",
"$LIB_FILE" =>
"package $appname;
use Dancer ':syntax';
our \$VERSION = '0.1';
get '/' => sub {
template 'index';
};
true;
",
'style.css' =>
'
body {
font-family: \'Linux Libertine\', Palatino, \'Palatino Linotype\', \'Book Antiqua\', Georgia, \'Times New Roman\', serif;
margin: 0;
margin-bottom: 25px;
padding: 0;
background-color: #ddd;
background-image: url("/images/perldancer-bg.jpg");
background-repeat: no-repeat;
background-position: top left;
font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
font-size: 13px;
color: #333;
}
h1 {
font-size: 28px;
color: #000;
}
a {color: #03c}
a:hover {
background-color: #03c;
color: white;
text-decoration: none;
}
#page {
background-color: #ddd;
width: 750px;
margin: auto;
margin-left: auto;
padding-left: 0px;
margin-right: auto;
}
#content {
background-color: white;
border: 3px solid #aaa;
border-top: none;
padding: 25px;
width: 500px;
}
#sidebar {
float: right;
width: 175px;
}
#header, #about, #getting-started {
padding-left: 75px;
padding-right: 30px;
}
#header {
background-image: url("/images/perldancer.jpg");
background-repeat: no-repeat;
background-position: top left;
height: 64px;
}
#header h1, #header h2 {margin: 0}
#header h2 {
color: #888;
font-weight: normal;
font-size: 16px;
}
#about h3 {
margin: 0;
margin-bottom: 10px;
font-size: 14px;
}
#about-content {
background-color: #ffd;
border: 1px solid #fc0;
margin-left: -11px;
}
#about-content table {
margin-top: 10px;
margin-bottom: 10px;
font-size: 11px;
border-collapse: collapse;
}
#about-content td {
padding: 10px;
padding-top: 3px;
padding-bottom: 3px;
}
#about-content td.name {color: #555}
#about-content td.value {color: #000}
#about-content.failure {
background-color: #fcc;
border: 1px solid #f00;
}
#about-content.failure p {
margin: 0;
padding: 10px;
}
#getting-started {
border-top: 1px solid #ccc;
margin-top: 25px;
padding-top: 15px;
}
#getting-started h1 {
margin: 0;
font-size: 20px;
}
#getting-started h2 {
margin: 0;
font-size: 14px;
font-weight: normal;
color: #333;
margin-bottom: 25px;
}
#getting-started ol {
margin-left: 0;
padding-left: 0;
}
#getting-started li {
font-size: 18px;
color: #888;
margin-bottom: 25px;
}
#getting-started li h2 {
margin: 0;
font-weight: normal;
font-size: 18px;
color: #333;
}
#getting-started li p {
color: #555;
font-size: 13px;
}
#search {
margin: 0;
padding-top: 10px;
padding-bottom: 10px;
font-size: 11px;
}
#search input {
font-size: 11px;
margin: 2px;
}
#search-text {width: 170px}
#sidebar ul {
margin-left: 0;
padding-left: 0;
}
#sidebar ul h3 {
margin-top: 25px;
font-size: 16px;
padding-bottom: 10px;
border-bottom: 1px solid #ccc;
}
#sidebar li {
list-style-type: none;
}
#sidebar ul.links li {
margin-bottom: 5px;
}
h1, h2, h3, h4, h5 {
font-family: sans-serif;
margin: 1.2em 0 0.6em 0;
}
p {
line-height: 1.5em;
margin: 1.6em 0;
}
code, tt {
font-family: \'Andale Mono\', Monaco, \'Liberation Mono\', \'Bitstream Vera Sans Mono\', \'DejaVu Sans Mono\', monospace;
}
#footer {
clear: both;
padding-top: 2em;
text-align: center;
padding-right: 160px;
font-family: sans-serif;
font-size: 10px;
}
',
# error.css
"error.css" =>
"body {
font-family: Lucida,sans-serif;
}
h1 {
color: #AA0000;
border-bottom: 1px solid #444;
}
h2 { color: #444; }
pre {
font-family: \"lucida console\",\"monaco\",\"andale mono\",\"bitstream vera sans mono\",\"consolas\",monospace;
font-size: 12px;
border-left: 2px solid #777;
padding-left: 1em;
}
footer {
font-size: 10px;
}
span.key {
color: #449;
font-weight: bold;
width: 120px;
display: inline;
}
span.value {
color: #494;
}
/* these are for the message boxes */
pre.content {
background-color: #eee;
color: #000;
padding: 1em;
margin: 0;
border: 1px solid #aaa;
border-top: 0;
margin-bottom: 1em;
}
div.title {
font-family: \"lucida console\",\"monaco\",\"andale mono\",\"bitstream vera sans mono\",\"consolas\",monospace;
font-size: 12px;
background-color: #aaa;
color: #444;
font-weight: bold;
padding: 3px;
padding-left: 10px;
}
pre.content span.nu {
color: #889;
margin-right: 10px;
}
pre.error {
background: #334;
color: #ccd;
padding: 1em;
border-top: 1px solid #000;
border-left: 1px solid #000;
border-right: 1px solid #eee;
border-bottom: 1px solid #eee;
}
",
"404.html" =>
Dancer::Renderer->html_page(
"Error 404",
'<h2>Page Not Found</h2><p>Sorry, this is the void.</p>',
'error'),
"500.html" =>
Dancer::Renderer->html_page(
"Error 500",
'<h2>Internal Server Error</h2>'
. '<p>Wooops, something went wrong</p>',
'error'),
'config.yml' =>
"# This is the main configuration file of your Dancer app
# env-related settings should go to environments/\$env.yml
# all the settings in this file will be loaded at Dancer's startup.
# Your application's name
appname: \"$name\"
# The default layout to use for your application (located in
# views/layouts/main.tt)
layout: \"main\"
# when the charset is set to UTF-8 Dancer will handle for you
# all the magic of encoding and decoding. You should not care
# about unicode within your app when this setting is set (recommended).
charset: \"UTF-8\"
# template engine
# simple: default and very basic template engine
# template_toolkit: TT
template: \"simple\"
# template: \"template_toolkit\"
# engines:
# template_toolkit:
# encoding: 'utf8'
# start_tag: '[%'
# end_tag: '%]'
",
'jquery.js' => jquery_minified(),
'MANIFEST.SKIP' => manifest_skip(),
'development.yml' =>
"# configuration file for development environment
# the logger engine to use
# console: log messages to STDOUT (your console where you started the
# application server)
# file: log message to a file in log/
logger: \"console\"
# the log level for this environement
# core is the lowest, it shows Dancer's core log messages as well as yours
# (debug, warning and error)
log: \"core\"
# should Dancer consider warnings as critical errors?
warnings: 1
# should Dancer show a stacktrace when an error is caught?
show_errors: 1
# auto_reload is a development and experimental feature
# you should enable it by yourself if you want it
# Module::Refresh is needed
#
# Be aware it's unstable and may cause a memory leak.
# DO NOT EVER USE THAT FEATURE IN PRODUCTION
# OR TINY KITTENS SHALL DIE WITH LOTS OF SUFFERING
auto_reload: 0
",
'production.yml' =>
'# configuration file for production environment
# only log warning and error messsages
log: "warning"
# log message to a file in logs/
logger: "file"
# don\'t consider warnings critical
warnings: 0
# hide errors
show_errors: 0
# cache route resolution for maximum performance
route_cache: 1
',
"001_base.t" =>
"use Test::More tests => 1;
use strict;
use warnings;
use_ok '$appname';
",
"002_index_route.t" =>
"use Test::More tests => 2;
use strict;
use warnings;
# the order is important
use $appname;
use Dancer::Test;
route_exists [GET => '/'], 'a route handler is defined for /';
response_status_is ['GET' => '/'], 200, 'response status is 200 for /';
",
};
}
sub write_bg {
my $path = shift;
my $data =<<'EOF';
M_]C_X``02D9)1@`!`0$`2`!(``#_VP!#``4#!`0$`P4$!`0%!04&!PP(!P<'
M!P\+"PD,$0\2$A$/$1$3%AP7$Q0:%1$1&"$8&AT='Q\?$Q<B)"(>)!P>'Q[_
MVP!#`04%!0<&!PX("`X>%!$4'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>
M'AX>'AX>'AX>'AX>'AX>'AX>'AX>'A[_P``1"`'T`?0#`2(``A$!`Q$!_\0`
M&0`!``,!`0````````````````(#!`$(_\0`*Q`!``("``4#!`,!`0$!````
M``$"`Q$$$B$Q,C-!41,B87$C0E(48H%#_\0`%`$!````````````````````
M`/_$`!01`0````````````````````#_V@`,`P$``A$#$0`_`/2H````````
M````````````````````````````````````````````````````````````
M````````````````````````YN#<?(.CG-'S!N/D'1S<?+H`````````````
M``````````````````````````````````````3T5VRUCWZ@L<W'RSVS3VA7
M-IGW!JMDK"$YZ^S/N7`73GGV1G->?=`!*<EI]W.>WRY$2[R6^`.:3FGY=BEI
M]G)I8#GM\NQDM'NYRRY,2"R,U_E*,_RI<!JKFK*=;1/NQ.[GY!N&.N2U5U,\
M?V!<(UO6W:4@```````````````````````````````````````GHJR98KVZ
M@LF8B-RKOFB/'JHM>UI[H`G?):WNB1&^R=,5K>V@5I169[0OKBK7REV;TKXQ
"$@H`
M:XK3WA9&"/>7>>]NU9@C'>W>TP!R8Z^[O-BCX(Q?,[2C'3X!'ZE/:(<^K'^8
M6<E/\G+7X!7.2?:I]3_RMY:_!RU^`5?5CWB'?J8_>(3Y*_Y@Y*?Y@$/XI]X<
MG%2W:4IQ5]NCDXI]K:!"V"8[=5<X[Q[+=9*^\R[]6W:U`9YC3C5_':/:)1M@
M]XD%$3,=I64S3'24+4M7O"(-E<E;>_5-AB9CLLQYICOU!J$:7BT=)2``````
M```````````````````````````1M:*QN4<F2*_MFO>;3N03R99MTCI"MQ.E
M)MV!&(WV64PS;K/1;6E,<;GNC-[7G5.@)17'2/:9<G):W2L3#M<6^MNZR(B(
MU`*HQVGRE.N.L=H3`````````````')B)[N@*[8JSVZ2A,9*>^X7@*8R1;I:
M-%L5;>,PLM2MNZJ:7IUK/0%5Z36>R#57)%OMM'5#)A]Z@IK,UG<-&++$])9Y
MB8GJX#>,N++->D]FFMHM&X!T```````````````````````````!3ERZZ1W<
MS9==(4`3,S/4(B9G4-&/'6D<U@1Q8M];)VR17[:1U1M:UYU6.BS'CBL?,@A7
M'-IW>5L1$1J'0`<M.HVY6T2"3EIU#J-XW`(UO.^KO-//HIJ8_+G_`.H.Q:>;
<16TS:8E'^^W:=Y`M>=ZAV;?;N'*QN\NVCEIH"@``
MVM,]DT*3$]$Y!7SSS?A.;=-H6B*__7;>,`5M,SJ2]IB=1W1CR=MZD`E2VXZH
MS>=_ARGN>T@LK.XVZCC\(2`$(O&])@A?'%OPK^_'^E[DQON"N8IEA1DI-)ZK
MKXYB>:KM;Q;[;QJ094\=YK*67%->L=E0-M+Q:.B3%2TUG<-6.\7C\@F`````
M```````````````````ISY-1J'<V3EC4=V:9W.P)ZNUK-IU#E8F9U#32L8Z;
MGN!2M<==SW1^[+;X@K%LEMSV71$1&H`K6*QJ(=```'+1N-(TIRI@#EITZY:-
MP"$]+;@CU/\`X[6D[ZR[R_?L$)Z[,?NG%>KE:ZF9!&LZO,NVGFIMVU-SN)=F
MOVZ@'*1":%:VB>Z4]@0\K?IW)VASDM$[B4];KJ05QY.V]2':TF)W,NWKOK'<
M$<?NY;4Q,IUKJ$9I.^_0$L?A"3D1J-.@A%/NVF```"O)CB>L=)6`*:7U/+='
M+BU]U>RW)2+1^4,=IK/)?L#.ECM-9VGGQZ^ZO92#;2T6C<),>*\UG\-=9BT;
M@'0```````````````````$<EHK7<NS.HVRYK\UOP"-K3:=RY$;EQ?@IK[K`
MECI%*\TN1O+?\%IG)?4=H75B*QJ`(B(C4.N6G4;9YSWW[`TC-]>_X/KW_`-(
MSQGGW3KFK/<%HY$Q,='0`49,UJWF([`O&;Z]_P`'U[_@&D9OKW_!]>_X!I&;