summaryrefslogtreecommitdiff
path: root/gsoc/2011-07-27-current-state-dancer-script.org
blob: 579f09f6b7a10290abcd789a9ae4d545d3722df9 (plain)
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
#+title:         Current State of Dancer::Script
#+date:          2011-07-27
#+layout:        post
#+category:      gsoc

Now that more than half of the program of GSoC has passed, Franck
asked for me to do a write-up of my work, so everybody can check it
and evaluate to see if it can be merged with the current devel repo of
Dancer.

You can check my whole work at [[https://github.com/gnusosa/Dancer][my repo in github]], and if you care to
make changes, just PR at will *:)*

*** Introducing Dancer::Script
Dancer::Script module is a mash-up between the old script/dancer
utility that we currently use to scaffold every new Dancer application
and some other content that I added with management from Sawyer and
Franck.

Dancer::Script makes use of Dancer::Object and Dancer::Logger, the
last so we can get better log outputs from the whole scaffolding
process

*** So what happened to =script/dancer= executable?

Well, it became a 8 lines executables that only calls =Dancer::Script=
*:D*

#+begin_src perl
#!/usr/bin/perl

use strict;
use warnings;

use Dancer::Script;

Dancer::Script->init->run;
#+end_src

In the same matter, I modified =dispatch.cgi= and =dispatch.fcgi= so
it will call =Dancer::Script=.

=dispatch.fcgi=

#+begin_src perl
#!/usr/bin/env perl

use Dancer::Script;

Dancer::Script->run_scaffold('fcgi');
#+end_src

=Dancer::Script::run_scaffold_cgi= and
=Dancer::Script::run_scaffold_fcgi= runs the code for the deployment
of =CGI= and =FastCGI=. This way, every new change in Plack/PSGI that
the team encounters and wish to add, can be directly added to
=Dancer::Script= without the need of scaffolding a new Dancer
application in every update that is done to Dancer. Since there are
common releases and quick-updates in between weeks, I believe that
this is a justified method.

*** Verbose output
Now that =Dancer::Script= makes use of =Dancer::Logger=, the following
methods replaced good ol' =print=, the methods =error()= and
=debug()=.

So if we do =dancer -a Hello::World= we get a pretty output like the
following:

#+begin_src sh
Carlos-Computer:test $ dancer -a Hello::World
debug> Writing directory: Hello-World
debug> Successfully wrote the directory: Hello-World
debug> Writing directory: Hello-World/bin
debug> Successfully wrote the directory: Hello-World/bin
debug> Writing file: Hello-World/bin/app.pl
debug> Successfully wrote: Hello-World/bin/app.pl
.............
#+end_src

The same goes for =error()=

#+begin_src sh
Carlos-Computer:test $ dancer -a 1World
error> Error: Invalid application name.
error> Application names must not contain colons, dots, hyphens or start with a number.
Carlos-Computer:test $
#+end_src

*** Is that all?
Well, feature-wise speaking it is. But the other good part is that
=Dancer::Script= is fully an object module that can be run without
=script/dancer=. For example:

#+begin_src perl
#!/usr/bin/perl

use strict;
use warnings;

use Dancer::Script;

Dancer::Script->init(appname => 'Hello::World', path => '/home/gnusosa/')->run;
#+end_src

So if you need to do something really specific with =Dancer::Script=,
you don't need to call =script/dancer= and run your automagically
work.

*** But that's not all!
Now that we have =Dancer::Script=, it will allow for future
subclassing for extra features that anybody could write themselves.
We'll also be able to easily add plugins so we could have flavors of
=Dancer::Script=. Just like the ones that create a =Dist::Zilla= based
dist or a Dancer plugin dist, etc... A lot of possibilities. *:)*

This is the current state of my work, I hope you like it, and expect
feedback of all kind. Thanks for your time. =:)=