Problem with an open filehandler within the route
Hi, I have the follow route: {{{ get qr{/(tests/.*)} => sub { my ($filename) = splat; my $testdata = {}; open my $stdout, "-|", "cli","--flag",$filename; while(<$stdout>) { my ($id,$name) = split/:/,$_; $testdata->{$id} = qq{$name}; } template 'show_test_case', { filename => $filename, testdata => $testdata, }; }; }}} Following the route (/tests/something) for the first time gives the expected results, meaning the list of $id's and $name's. But when executing the route for the second time, it shows the follow runtime error: " Warning caught during route execution: readline() on closed filehandle $stdout " Is there some limitation for working with filehandlers withing the route subroutine? Thomas
That's odd. The routes are just saved and rerun every time, but they're enclosed scopes so that shouldn't happen. I'm probably too tired and not smart enough to clearly see something simple that's happening here. My suggestion is: close the damn filehandle when you're done with it! :) Sawyer. On Tue, Feb 15, 2011 at 3:22 PM, Thomas Maier <hayzer@gmail.com> wrote:
Hi, I have the follow route: {{{
get qr{/(tests/.*)} => sub { my ($filename) = splat; my $testdata = {}; open my $stdout, "-|", "cli","--flag",$filename; while(<$stdout>) { my ($id,$name) = split/:/,$_; $testdata->{$id} = qq{$name}; } template 'show_test_case', { filename => $filename, testdata => $testdata, }; };
}}}
Following the route (/tests/something) for the first time gives the expected results, meaning the list of $id's and $name's. But when executing the route for the second time, it shows the follow runtime error: " Warning caught during route execution: readline() on closed filehandle $stdout "
Is there some limitation for working with filehandlers withing the route subroutine?
Thomas _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
You are not checking whether the open() is successful or not (unless you're using autodie or Fatal, which is not shown here). I suspect this might have something to do with your error. Cheers, Flavio. On Tue, Feb 15, 2011 at 2:22 PM, Thomas Maier <hayzer@gmail.com> wrote:
Hi, I have the follow route: {{{
get qr{/(tests/.*)} => sub { my ($filename) = splat; my $testdata = {}; open my $stdout, "-|", "cli","--flag",$filename; while(<$stdout>) { my ($id,$name) = split/:/,$_; $testdata->{$id} = qq{$name}; } template 'show_test_case', { filename => $filename, testdata => $testdata, }; };
}}}
Following the route (/tests/something) for the first time gives the expected results, meaning the list of $id's and $name's. But when executing the route for the second time, it shows the follow runtime error: " Warning caught during route execution: readline() on closed filehandle $stdout "
Is there some limitation for working with filehandlers withing the route subroutine?
Thomas _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
I ran into this same error yesterday in a non-Dancer env. I was trying to open a file that didn't exist and wasn't checking success. On Tue, Feb 15, 2011 at 10:02 AM, Flavio Poletti <polettix@gmail.com> wrote:
You are not checking whether the open() is successful or not (unless you're using autodie or Fatal, which is not shown here). I suspect this might have something to do with your error.
Cheers,
Flavio.
Le 15/02/2011 16:02, Flavio Poletti a écrit :
You are not checking whether the open() is successful or not (unless you're using autodie or Fatal, which is not shown here). I suspect this might have something to do with your error.
Indeed, It is not a Dancer-related issue (no reason it could be). Just check the return value of open() and you'll see what's going on ;) -- Alexis Sukrieh
On 2/15/2011 5:09 PM, Alexis Sukrieh wrote:
Le 15/02/2011 16:02, Flavio Poletti a écrit :
You are not checking whether the open() is successful or not (unless you're using autodie or Fatal, which is not shown here). I suspect this might have something to do with your error.
Indeed,
It is not a Dancer-related issue (no reason it could be). Just check the return value of open() and you'll see what's going on ;) I checked. And it is now: Dancer 1 - me 0. It was very unwise not to check this before I bothered you all. Sorry.
Thomas
No worries, we're to support! :) On Feb 15, 2011 5:54 PM, "Thomas Maier" <hayzer@gmail.com> wrote: On 2/15/2011 5:09 PM, Alexis Sukrieh wrote: > > Le 15/02/2011 16:02, Flavio Poletti a écrit : >> >> ... I checked. And it is now: Dancer 1 - me 0. It was very unwise not to check this before I bothered you all. Sorry. Thomas _______________________________________________ Dancer-users mailing list Dancer-users@perldance...
participants (5)
-
Alexis Sukrieh -
Flavio Poletti -
Jonathan Hogue -
sawyer x -
Thomas Maier