Write a Filehandle w/Dancer2by hardburn (Abbot)
|on Aug 13, 2014 at 23:13 UTC||Need Help??|
hardburn has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write out a filehandle using Dancer2. The data may come from a live video stream, so the filehandle must be streamed in chunks, not returned all at once.
The documention for Dancer2::Manual has this to say about send_file():
"You can use around to get all the content (whether a filehandle if it's a regular file or a full string if it's a scalar ref) and decide what to do with it"
This and the example code suggests to me that I can pass the filehandle as the first argument to send_file(), and then the around callback will get the filehandle as its second argument. Here's an attempt at that:
This results in the error:
OK, so the first argument can't be a filehandle. Maybe I can pass a dummy string as a scalar ref (which is documented to work) and then have the callback use $in_fh directly as a closure:
But the output of this is "foo", as if the callback is not being used at all.
OK, let's try passing a dummy file and see if the callback is called:
Even with system_path and /dev/zero existing on my system, this gives an HTTP 404 error.
Is there any way to coerce Dancer2 into streaming the filehandle? It feels like this shouldn't require callbacks at all, just:
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.