<!-- BootStrap NavBar -->
<div class="navbar">
  <div class="navbar-inner">
    <div class="container">
	<h3><a class="brand" href="[% request.uri_base %]"><img src="images/dancer_man.png"> Perl Dancer</a></h3>
    </div>
  </div>
</div>

<!-- HEADER line -->
<div class="container">

<div class="page-header">
	<div class="row">
		<div class="span12">
			<h2>Dancer + Bootstrap Examples</h2>
			<h1>Dynamic Content Generation</h1>
		</div>
	</div>
</div>

<div class="row">
	<div class="span12">

	This example shows how to return dynamic content (generated by the Perl/Dancer script) to the user.
	<br/>
	Useful if you need to send data to the client, that is not based on a physical file or a variable in memory (or if the data is too big to fit in memory).
	<br/>
	<br/>
	<br/>

	<h3>Code Highlights</h3>
	<ul>
		<li>The Dancer code is in
                    <a href="[% request.uri_for("/show_file",file => "dynamic_content.pm", example => "Dynamic Content", url => request.uri_for("/dynamic_content") ) %]">
                    <code>./lib/examples/dynamic_content.pm</code> <i class="icon-eye-open"></i> </a>.
                </li>

		<li>This HTML template is in
                    <a href="[% request.uri_for("/show_file",file => "dynamic_content.tt", example =>"Dynamic Content", url => request.uri_for("/dynamic_content") ) %]">
                    <code>./views/examples/dynamic_content.tt</code> <i class="icon-eye-open"></i> </a>.
                </li>
		<li>This is functionally equivalent to the following 'classic' CGI code:
<pre>
#!/usr/bin/perl
use CGI qw/:standard/;

print header(-type=>"text/plain", -attachment=>"foo.txt");

foreach $line ( 1 .. 10000 ) {
	print "Hello World (line $line)\n";
}
</pre>
		</li>
		<li>Due the Dancer architecture, we can't simply <code>print</code> the data we want to send to the use (as in classic CGI programs). Instead, we supply a callback <code>sub</code> which will send the data to the user.</li>
		</li>
		<li>Using <code>send_file</code> with the <b>streaming</b> parameter, we create a subroutine that will send the data back to the user.</li>
		<li>See the <b>dynamic_content.pm</b> perl module for a detailed example.</li>
	</ul>

	</div>
</div>

<br/>
<br/>
<br/>

<div class="row">
	<div class="span12">
		<h1>Download</h1>
		Clicking this button will send you a 25MB text file.<br/>
		The content is dynamically generated by the Dancer code.<br/>
		<a class="btn btn-primary" href="[% request.uri_for("/dynamic_content_download") %]">Download Dynamic Content</a>
	</div>
</div>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>