What's put me off implementing the sub _dancer approach is that (as far as I
can see) you need to do that in every module that provides routes, which might
be dozens; it would be preferable not to have to go through each one and make
sure they're in a _dance block. If you mix routes and functions... I guess it
would still work, but it would feel a bit strange having other subs within sub
_dance{...}.
Paul's email has triggered a thought, and indeed the following hack works for
me (on Dancer1 anyway, which is present on the machine I'm on right now). There
is probably a much better way of generating $name that won't cause conflicts
(maybe refaddr?). The question is - where should something like this go?
sub get {
my $route = shift;
my $code = shift;
my $name = $route =~ s/[^a-z0-9]/_/rig;
my ($pkg) = caller;
Sub::Install::install_sub({
code => $code,
into => $pkg,
as => $name
}) if 1;
Dancer::get $route, $code;
}
# Setting "if 1" to "if 0" falsely gives me 100% coverage, so it's definitely
the install_sub that's doing it.
Daniel
-----Original Message-----
From: dancer-users [mailto:[email protected]] On Behalf Of Paul
Johnson
Sent: 17 March 2015 10:02
To: Perl Dancer users mailing list
Subject: Re: [dancer-users] Devel::Cover and Dancer
On Tue, Mar 17, 2015 at 11:25:53AM +0200, Gabor Szabo wrote:
> When last time I ran the tests of my Dancer2 based app through
> Devel::Cover it did not provide any report for the routes. If I use
> names subroutines and set them as
>
> get '/' => \&serve_index;
> sub serve_index {
> }
>
> then Devel::Cover takes those subs into account.
>
> Do you know how can I convince Devel::Cover to report properly even
> with anonymous subs?
This is something I still want to fix within Devel::Cover if I can. But for
now, the best workaround that I have is to put everything into a sub and call
that:
sub _dancer {
get '/' => sub {
}
get '/login' => sub {
}
}
_dancer;
Not ideal, but perhaps the best of a bad bunch. Unless anyone has a better
suggestion?
--
Paul Johnson - [email protected]
http://www.pjcj.net
_______________________________________________
dancer-users mailing list
[email protected]
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.
_______________________________________________
dancer-users mailing list
[email protected]
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users