A look at the source code help to understand what is going on:
sub builder(&) {
my $block = shift;
...
my $app = $block->();
if ($mount_is_called) {
if ($app ne $urlmap) {
Carp::carp("WARNING: You used mount() in a builder block,
So, builder
is just a subroutine and its argument is a code block. That code block is evaluated and the result ends up in $app
. With your code, however, the result of the evaluation is the empty string which results from the terminating foreach
loop:
$ perl -MData::Dumper -e 'sub test{ for("a", "b"){ $_ } }; print Dumper(test())'
$VAR1 = '';
Since mount foo => $bar
is "just" syntactic sugar that even gets hard to read in cases like yours, I suggest you move a tiny step towards the bare metal, skip the syntactic sugar and use Plack::App::URLMap directly:
use strict;
use warnings;
use Plack::App::URLMap;
my $app = sub {
return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello World' ] ];
};
my $map = Plack::App::URLMap->new;
foreach my $act ( qw( /some/aa /another/bb / ) ) {
$map->mount( $act => $app );
}
$map->to_app;