[dancer-users] Confused about types and globals
David Golden
xdg at xdg.me
Thu Jan 23 14:58:25 GMT 2014
On Thu, Jan 23, 2014 at 9:18 AM, Warren Young <warren at etr-usa.com> wrote:
> get '/foo/*' => sub { ....
>
> What is "get", exactly? I assume it is a function that takes a string and a
> coderef, and you're taking advantage of Perl's optional parentheses and fat
> comma to create a Perl-based DSL.
Exactly. A lot of Dancer is Perl-based DSL. It "prettier" than this:
get( '/foo/*', sub { ... } )
> I tried to answer this myself before posting. I thought it might be a
> package-global function, but there is no "sub get" in Dancer2.pm.
Dancer2 (unlike Dancer1) has a rather convoluted system for exporting
functions to the right place. It's sort of defined in
Dancer2::Core::DSL, but those functions get wrapped in something that
provide the right "application" object when used. E.g.
https://metacpan.org/source/XSAWYERX/Dancer2-0.11/lib/Dancer2/Core/DSL.pm#L150
> Another example: context->destroy_session
>
> The only way I can think of for that to work without a sigil is for
> 'context' to be another global (?) function that returns an object
> reference, rather than be an object reference itself.
Exactly.
> There is no "context" in Dancer2.pm, so I'm left wondering where it comes
> from.
It's another DSL keyword:
https://metacpan.org/source/XSAWYERX/Dancer2-0.11/lib/Dancer2/Core/DSL.pm#L269
> I care about this because I'm trying to port a fairly complex app from
> Apache::ASP to Dancer2, and this app is already broken up into many separate
> modules.
As I've mentioned before on this list, I consider Dancer2 to be alpha
quality as it is still in active development and is thus not stable
(though it is getting better). I would absolutely not port anything
important or complex to Dancer2.
David
--
David Golden <xdg at xdg.me>
Take back your inbox! → http://www.bunchmail.com/
Twitter/IRC: @xdg
More information about the dancer-users
mailing list