I'm writing a webdav server (it works, yay!), but now I'm looking at polishing the edges before I release. A webdav server, for those who aren't up on their jargon, is a HTTP fileserver. One of the things I have observed is that good clients will update the screen as the information flows in (in XML). Now naturally I did the code in good procedural style - one routine gets the list of files, another builds the XML. But this means I build the entire XML document before I send it - leading to the feeling of slowness on the client side.
The meta-code looks like this:
PROPFIND {
get_properties_recursive{
while properties
get_property_nonrec
generate_xml_chunkette
loop
return xml_chunks
}
add_xml_header_and_footer
return xml_document
}
There are obvious things I could do, like pass in the HTTP::Daemon object, and print each chunk as I generate it. But this breaches functional and procedural coding guidlines as I understand them. I will have duplicated server output routines, and my code will not be obvious.
A while ago I heard about something called continuations, which perl doesn't have, but they sound ideal. My current plan is to completely turn my routines inside out (ouch), and hand a code ref to HTTP::Daemon, which it will then call for each chunk of XML (functional style). This will require messy state switches and other yick. Before I do this, would anyone care to recommend a better approach?
____________________
Jeremy
I didn't believe in evil until I dated it.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.