<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>transfixed but not dead! &#187; Squatting</title>
	<atom:link href="http://transfixedbutnotdead.com/tag/squatting/feed/" rel="self" type="application/rss+xml" />
	<link>http://transfixedbutnotdead.com</link>
	<description>my ramblings on life, work &#38; anything left in-between</description>
	<lastBuildDate>Fri, 03 Feb 2012 16:03:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='transfixedbutnotdead.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/0a317653027efb1ab2bf8adde3dcb067?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>transfixed but not dead! &#187; Squatting</title>
		<link>http://transfixedbutnotdead.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://transfixedbutnotdead.com/osd.xml" title="transfixed but not dead!" />
	<atom:link rel='hub' href='http://transfixedbutnotdead.com/?pushpress=hub'/>
		<item>
		<title>Why Squatting?</title>
		<link>http://transfixedbutnotdead.com/2009/08/20/why-squatting/</link>
		<comments>http://transfixedbutnotdead.com/2009/08/20/why-squatting/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 09:02:19 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Camping]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Squatting]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=533</guid>
		<description><![CDATA[Below are two tutorial examples of Camping, a Web Microframework written in Ruby. Alongside them are my two conversions written in Squatting, a Camping-inspired Web Microframework for Perl, written by John Beppu &#160; The Camping Short, Short Example: The Squatting Short, Short Example: &#160; The Camping Tutorial Two: The Squatting Tutorial Two: I&#8217;m not going [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=533&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Below are two tutorial examples of <a href="http://camping.rubyforge.org">Camping</a>, a Web Microframework written in Ruby.</p>
<p>Alongside them are my two conversions written in <a href="http://search.cpan.org/dist/Squatting/">Squatting</a>, a Camping-inspired Web Microframework for Perl, written by <a href="http://search.cpan.org/~beppu/">John Beppu</a></p>
<p>&nbsp;</p>
<p>The Camping Short, Short Example:<br />
<pre class="brush: ruby;">
require 'camping'

Camping.goes :HomePage

module HomePage::Controllers

  # The root slash shows the `index' view.
  class Index &lt; R '/'
    def get
      render :index 
    end
  end

  # Any other page name gets sent to the view
  # of the same name.
  #
  #   /index -&gt; Views#index
  #   /sample -&gt; Views#sample
  #
  class Page &lt; R '/(\w+)'
    def get(page_name)
      render page_name
    end
  end

end

module HomePage::Views

  # If you have a `layout' method like this, it
  # will wrap the HTML in the other methods.  The
  # `self &lt;&lt; yield' is where the HTML is inserted.
  def layout
    html do
      title { 'My HomePage' }
      body { self &lt;&lt; yield }
    end
  end

  # The `index' view.  Inside your views, you express
  # the HTML in Ruby.  See http://code.whytheluckystiff.net/markaby/.
  def index
    p 'Hi my name is Charles.'
    p 'Here are some links:'
    ul do
     li { a 'Google', :href =&gt; 'http://google.com' }
     li { a 'A sample page', :href =&gt; '/sample' }
    end
  end

  # The `sample' view.
  def sample
    p 'A sample page'
  end
end
</pre></p>
<p>The Squatting Short, Short Example:<br />
<pre class="brush: perl;">
use strict;
use warnings;

{
  package ShortShortExample;
  use base 'Squatting';
}

{
  package ShortShortExample::Controllers;
  use Squatting ':controllers';
  
  our @C = (

    C( 
      Index =&gt; [ '/' ],
      get   =&gt; sub {
        my ( $self ) = @_;
        $self-&gt;render( 'index' );
      },
    ),
    
    C(
      Page =&gt; [ '/(\w+)' ],
      get  =&gt; sub {
        my ( $self, $page_name ) = @_;
        $self-&gt;render( $page_name );
      }
    ),
    
  );
}

{
  package ShortShortExample::Views;
  use Squatting ':views';
  use HTML::AsSubs;
    
  our @V = (
    
    V(  'html',
      
      layout =&gt; sub {
        my ( $self, $v, @yield ) = @_;
        html(
          title ( 'My HomePage' ),
          body ( @yield ),
        )-&gt;as_HTML;
      },
      
      index =&gt; sub {
        my ( $self, $v ) = @_;
        return (
          p ( 'Hi my name is Charles.' ),
          p ( 'Here are some links:'   ),
          ul (
            li ( a( { href =&gt; 'http://google.com' },  'Google' ) ),
            li ( a( { href =&gt; '/sample' },  'a sample page'    ) ),
          ),
        );
      },
      
      sample =&gt; sub {
        my ( $self ) = @_;
        p ( 'A sample page' );
      },
            
    ),
  );
}

1;
</pre></p>
<p>&nbsp;</p>
<p>The Camping Tutorial Two:<br />
<pre class="brush: ruby;">
require 'camping'

Camping.goes :Nuts

module Nuts::Controllers
  class Index &lt; R '/'
    def get
      @t = Time.now.to_s
      render :sundial
    end
  end
end

module Nuts::Views
  def layout
    html do
      head do
        title { &quot;Nuts And GORP&quot; }
      end
      body { self &lt;&lt; yield }
    end
  end

  def sundial
    p &quot;The current time is: #{@t}&quot;
  end
end
</pre></p>
<p>The Squatting Tutorial Two:<br />
<pre class="brush: perl;">
use strict;
use warnings;

{
  package Nuts;
  use base 'Squatting';
}

{ 
  package Nuts::Controllers;
  use Squatting ':controllers';
  
  our @C = (
    C(
      Index =&gt; [ '/' ],
      get   =&gt; sub { 
        my ( $self ) = @_;
        my $v = $self-&gt;v;
        $v-&gt;{t} = localtime;
        $self-&gt;render( 'sundial' );
      },
    ),
  );
}

{
  package Nuts::Views;
  use Squatting ':views';
  use HTML::AsSubs;
  
  our @V = (
    V(  'html',
    
      layout =&gt; sub { 
        my ( $self, $v, @yield ) = @_;
        html (
          head ( 'Nuts And GORP' ),
          body ( @yield ),
        )-&gt;as_HTML;
      },
      
      sundial =&gt; sub {
        my ( $self, $v ) = @_;
        p ( &quot;The current time is: $v-&gt;{t}&quot; );
      },
    ),
  );
}

1;
</pre></p>
<p>I&#8217;m not going to say much more at this point because I think the code above clearly expresses what&#8217;s going on.  So just enjoy <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>/I3az/</p>
<p>&nbsp;</p>
<p>Postscript:</p>
<p>The two Camping tutorials were written by <a href="http://en.wikipedia.org/wiki/Why_the_lucky_stiff">Why the lucky stiff</a> the author of Camping.  These are no longer available on web because _why was regurgitating them from his own repo/website onto GitHub.   </p>
<p>I wrote the Squatting ports of the tutorial back in October 2008 so luckily I had pulled down these Camping tutorials.  I found that porting _why&#8217;s excellent Camping tutorials were a good way of learning Squatting.</p>
<p>The plan was always to post these on my blog.   In fact I have a long list of stuff to post ranging from just a few scribbles to completed prose.   I&#8217;m just trying to be &#8220;logical&#8221; about the order of these posts!</p>
<p>So why (excuse the pun!) post these now?    The reason will be obvious to most readers&#8230;.  _why&#8217;s strange disappearance from the web overnight.</p>
<p>I not going to conjecture further but I hope all is OK.   So this post is my little ode to _why.</p>
<p>Below are some links on this strange event:</p>
<ul>
<li><a href="http://news.ycombinator.com/item?id=773106">_why is no more (Hacker News)</a></li>
<li><a href="http://news.ycombinator.com/item?id=774384">_why&#8217;s best twitter posts (Hacker News)</a></li>
<li><a href="http://ejohn.org/blog/eulogy-to-_why/">Eulogy to _why (John Resig)</a></li>
<ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/533/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/533/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/533/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/533/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/draegtun.wordpress.com/533/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/draegtun.wordpress.com/533/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/draegtun.wordpress.com/533/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/draegtun.wordpress.com/533/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/533/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/533/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/533/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/533/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/533/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/533/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=533&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2009/08/20/why-squatting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>Squatting 0.60 hits CPAN</title>
		<link>http://transfixedbutnotdead.com/2009/04/27/squatting-060-hits-cpan/</link>
		<comments>http://transfixedbutnotdead.com/2009/04/27/squatting-060-hits-cpan/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 18:19:08 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[catalyst]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Squatting]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=283</guid>
		<description><![CDATA[Hot on the hooves of Catalyst 5.8 (CataMoose) hitting CPAN came the latest version of Squatting (web microframework) following very close on its tail. Here are some new things to look out for in latest Squatting&#8230; More docs Squatting::With::Logs &#8211; Simple way to log errors Squatting::With::Coro::Debug &#8211; Use Coro::Debug to help debug Squatting::On::Continuity apps Can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=283&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hot on the hooves of <a href="http://www.catalyzed.org/2009/04/catalyst-58-released.html">Catalyst 5.8 (CataMoose)</a> hitting CPAN came the latest version of <a href="http://groups.google.co.uk/group/squatting-framework/browse_frm/thread/5e57e80f0e5e855d">Squatting (web microframework)</a> following very close on its tail.</p>
<p>Here are some new things to look out for in latest Squatting&#8230;</p>
<ul>
<li>More docs
<li><a href="http://search.cpan.org/dist/Squatting/lib/Squatting/With/Log.pm">Squatting::With::Logs</a>  &#8211; Simple way to log errors
<li><a href="http://search.cpan.org/dist/Squatting/lib/Squatting/With/Coro/Debug.pm">Squatting::With::Coro::Debug</a> &#8211; Use <a href="http://search.cpan.org/dist/Coro/Coro/Debug.pm">Coro::Debug</a> to help debug Squatting::On::Continuity apps
<li>Can now squat on <a href="http://search.cpan.org/dist/Squatting/lib/Squatting/On/MP13.pm">mod_perl 1.3</a> &amp; <a href="http://search.cpan.org/dist/Squatting/lib/Squatting/On/MP20.pm">mod_perl 2.0</a>
<li>And a little extra stocking filler called <a href="http://search.cpan.org/dist/Squatting/lib/Squatting/H.pm">Squatting::H</a>
</ul>
<p>Squatting::H is hash based object loosely based on <a href="http://camping.rubyforge.org/classes/Camping/H.html">Camping::H (Ruby)</a>.   Here is an example from its pod to make you puurrrr a little <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><pre class="brush: perl;">
my $cat = Squatting::H-&gt;new({
    name =&gt; 'kurochan',
    meow =&gt; sub { &quot;me&quot; . &quot;o&quot; x length($_[0]-&gt;name) . &quot;w&quot; }
});

my $kitty = $cat-&gt;clone({ name =&gt; 'max' });

$cat-&gt;name;                     # &quot;kurochan&quot;
$kitty-&gt;name;                   # &quot;max&quot;
$cat-&gt;meow;                     # &quot;meoooooooow&quot;
$kitty-&gt;meow;                   # &quot;meooow&quot;
$cat-&gt;age(3);                   # 3
$kitty-&gt;age(2);                 # 2
$kitty-&gt;slots;                  # qw(name meow age)
</pre></p>
<p>/I3az/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/draegtun.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/draegtun.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/draegtun.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/draegtun.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/283/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=283&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2009/04/27/squatting-060-hits-cpan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>The 140 Character WebApp Disclaimer!</title>
		<link>http://transfixedbutnotdead.com/2009/02/23/the-140-character-webapp-disclaimer/</link>
		<comments>http://transfixedbutnotdead.com/2009/02/23/the-140-character-webapp-disclaimer/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 11:21:07 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Squatting]]></category>

		<guid isPermaLink="false">http://draegtun.wordpress.com/?p=184</guid>
		<description><![CDATA[Re: my last blog post Disclaimer &#8211; While its fun to play don&#8217;t go writing your webapps in non strict pigeon bad Perl like my post &#160; And also remember to treat all input as dangerous and only output well formed HTML please!! I&#8217;ve formatted the one liners below so that you can see what [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=184&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Re: <a href="http://draegtun.wordpress.com/2009/02/23/the-140-character-webapp/">my last blog post</a></p>
<p>Disclaimer &#8211; While its fun to play don&#8217;t go writing your webapps in non strict pigeon bad Perl like my post <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   &nbsp;   And also remember to treat all input as dangerous and only output well formed HTML please!!</p>
<p>I&#8217;ve formatted the <a href="http://en.wikipedia.org/wiki/One-liner_program">one liners</a> below so that you can see what is going on (at least a bit better!)&#8230;.</p>
<p>Squatting micro-twitter ( W.pm )&#8230;</p>
<p><pre class="brush: perl;">
package W;
use base 'Squatting';


package W::Controllers;
use Squatting':controllers';

@C = C ( 
  w =&gt; ['/'], 
  get =&gt; sub { 
    ($s) = @_;
    unshift @w, $s-&gt;input-&gt;{m};
    $s-&gt;v-&gt;{m} = \@w;
    $s-&gt;render('w')
  });


package W::Views;
use Squatting ':views';

@V = V( '',
  w =&gt; sub {
    my $r;
    $r .= &quot;&lt;hr&gt;$_&quot; for@{$_[1]-&gt;{m}};
    return '&lt;form&gt;&lt;input name=m&gt;'.$r
  });

1;
</pre></p>
<p>Continuity micro-twitter&#8230;<br />
<pre class="brush: perl;">
use Continuity;
Continuity-&gt;new-&gt;loop;

sub main {
  ($r) = @_;
  while (1) {
    $r-&gt;print('&lt;form&gt;&lt;input name=m&gt;');
    $r-&gt;print('&lt;hr&gt;',$_) for @b;
    $r-&gt;next;
    unshift @b, $r-&gt;param('m')
  }
}
</pre></p>
<p>Continuity micro-twitter (save state to file)&#8230;<br />
<pre class="brush: perl;">
use Continuity;
Continuity-&gt;new-&gt;loop;

sub main {
  ($r) = @_;
  while (1) {
    $r-&gt;print('&lt;form&gt;&lt;input name=m&gt;');
    open F, '+&lt;0';
    $r-&gt;print('&lt;hr&gt;',$_) for reverse &lt;F&gt;;
    $r-&gt;next;
    print F $r-&gt;param('m'), &quot;\n&quot;
  }
}
</pre></p>
<p>Continuity number counter Twitter compliant webapp!&#8230;<br />
<pre class="brush: perl;">
use Continuity;
Continuity-&gt;new-&gt;loop;

sub main {
  ($r) = @_;
  while (1) {
    $r-&gt;print('&lt;form&gt;&lt;input name=m&gt;');
    $r-&gt;next;
    $x += $r-&gt;param('m');
    $r-&gt;print($x)
  }
}
</pre></p>
<p>When I get a mo I may post a &#8220;proper&#8221; Squatting micro-twitter webapp.</p>
<p>/I3az/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/draegtun.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/draegtun.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/draegtun.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/draegtun.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=184&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2009/02/23/the-140-character-webapp-disclaimer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>The 140 character webapp</title>
		<link>http://transfixedbutnotdead.com/2009/02/23/the-140-character-webapp/</link>
		<comments>http://transfixedbutnotdead.com/2009/02/23/the-140-character-webapp/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 10:57:20 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[continuity]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Squatting]]></category>

		<guid isPermaLink="false">http://draegtun.wordpress.com/?p=175</guid>
		<description><![CDATA[Anyone catch this The 140 Character WebApp Challenge&#8221; on Twitter recently? f055 as been able to create a webapp in Perl that can be posted in a Tweet! Pretty impressive. What also caught my eye was that some of the responses were using micro webframeworks like Camping &#38; Sinatra (despite original challenge saying only using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=175&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Anyone catch this <a href="http://f055.net/article/the-140-character-webapp-challenge/">The 140 Character WebApp Challenge&#8221;</a> on Twitter recently?</p>
<p><a href="http://twitter.com/f055">f055</a> as been able to create a webapp in Perl that can be posted in a Tweet!   Pretty impressive.</p>
<p>What also caught my eye was that some of the responses were using micro webframeworks like <a href="http://redhanded.hobix.com/bits/campingAMicroframework.html">Camping</a> &amp; <a href="http://www.sinatrarb.com/">Sinatra</a> (despite original challenge saying only using standard libraries!).</p>
<p>Still fair game&#8230;  so I&#8217;d thought I&#8217;d give it a shot with <a href="http://search.cpan.org/dist/Squatting/">Squatting</a>.   Here&#8217;s a Squatting version of the f055 micro-twitter webapp&#8230;..</p>
<p><pre class="brush: perl;">
package W;use base 'Squatting';package W::Controllers;use Squatting':controllers';@C=C(w=&gt;['/'],get=&gt;sub{($s)=@_;unshift@w,$s-&gt;input-&gt;{m};$s-&gt;v-&gt;{m}=\@w;$s-&gt;render('w')});package W::Views;use Squatting':views';@V=V('',w=&gt;sub{my $r;$r.=&quot;&lt;hr&gt;$_&quot;for@{$_[1]-&gt;{m}};return'&lt;form&gt;&lt;input name=m&gt;'.$r});1;
</pre></p>
<p>Nice eh <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   &nbsp;  Just type &#8220;squatting W.pm&#8221; and away u go.   And like Sinatra it has its own webserver!  (Squatting runs by default on <a href="http://continuity.tlt42.org/">Continuity</a>).</p>
<p>So weighs in at 297 chars so too big for Twitter <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />     &nbsp;&nbsp;Still it does well against the already published 308 chars Camping version but still a way to  go against the two published Sinatra versions with 140 &amp; 136 chars.</p>
<p>So can it be trimmed?   Not easily with those package declarations.  But how about a <a href="http://search.cpan.org/dist/Continuity/lib/Continuity.pm">Continuity</a> version!?</p>
<p><pre class="brush: perl;">
use Continuity;Continuity-&gt;new-&gt;loop;sub main{($r)=@_;while(){$r-&gt;print('&lt;form&gt;&lt;input name=m&gt;');$r-&gt;print('&lt;hr&gt;',$_)for @b;$r-&gt;next;unshift@b,$r-&gt;param('m')}}
</pre></p>
<p>This comes in at a very respectable 159 chars and with its own webserver (and just by doing perl program_name.pl).</p>
<p>However the keen eyed of you may have noticed something different about both Squatting &amp; Continuity scripts compared to what has already been so far posted in the challenge?  Mine are not saving state anywhere (ie. to a file).  And even more remarkable fire up Squatting app in another web browser and you see the state appear in both browsers.</p>
<p>Unfortunately though all this state is maintained in memory (in package variables in Squatting&#8217;s case).  So once these webapps are stopped then all is lost <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   &nbsp;   So to retain state after a restart you would have to revert to saving data to file.   Here&#8217;s an amended Continuity version&#8230;.</p>
<p><pre class="brush: perl;">
use Continuity;Continuity-&gt;new-&gt;loop;sub main{($r)=@_;while(){$r-&gt;print('&lt;form&gt;&lt;input name=m&gt;');open F,'+&lt;0';$r-&gt;print('&lt;hr&gt;',$_)for reverse&lt;F&gt;;$r-&gt;next;print F$r-&gt;param('m'),&quot;\n&quot;}}
</pre> </p>
<p>BTW.  Writing to file in a webapp isn&#8217;t a good idea.   You have to be careful of race conditions and locks.   Continuity uses co-routines so it should be OK compared to normal CGI stuff (I think?).</p>
<p>So now this Continuity micro-twitter comes in at 183 chars.   Not bad&#8230; but still not Twitter compliant <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Still challenge was a Twitter sized &#8220;webapp&#8221; and so here is a simple number accumulator written in Continuity&#8230;.</p>
<p><pre class="brush: perl;">
use Continuity;Continuity-&gt;new-&gt;loop;sub main{($r)=@_;while(){$r-&gt;print('&lt;form&gt;&lt;input name=m&gt;');$r-&gt;next;$x+=$r-&gt;param('m');$r-&gt;print($x)}}
</pre></p>
<p>And it comes it right on the mark at 140 chars <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>/I3az/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/draegtun.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/draegtun.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/draegtun.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/draegtun.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/175/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=175&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2009/02/23/the-140-character-webapp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>Pre-Render Template at Squatting start-up</title>
		<link>http://transfixedbutnotdead.com/2008/12/23/pre-render-template-at-squatting-start-up/</link>
		<comments>http://transfixedbutnotdead.com/2008/12/23/pre-render-template-at-squatting-start-up/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 20:50:21 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Squatting]]></category>
		<category><![CDATA[Template Toolkit]]></category>

		<guid isPermaLink="false">http://draegtun.wordpress.com/?p=120</guid>
		<description><![CDATA[In previous post I mentioned that you could build a static CSS file from a template when Squatting first starts up. Well here&#8217;s a complete example using Template Toolkit ( CSS.pm )&#8230;. $CSS::CONFIG{ pre_render } contains all the profiles to pre-render on. You just need to name a profile and tell it what template (tt), [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=120&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://draegtun.wordpress.com/2008/12/23/css-views-in-squatting/">previous post</a> I mentioned that you could build a static CSS file from a template when Squatting first starts up. </p>
<p>Well here&#8217;s a complete example using Template Toolkit ( CSS.pm )&#8230;.</p>
<p><pre class="brush: perl;">
use strict;
use warnings;

{
    package CSS;
    use base 'Squatting';
    use Template;
    
    
    BEGIN {
        our %CONFIG = (
            
            docroot  =&gt; './www',    # Continuity htdocs
            static   =&gt; '/static',  # Our unique prefix/folder under above
            
            pre_render =&gt; {
                
                # CSS profile
                css =&gt; {
                    tt   =&gt; 'css.tt',       # CSS template 
                    file =&gt; 'static.css',   # Name of static file to build
                    v    =&gt; {               # template variables
                        colour =&gt; 'red',
                    },
                },
                
                # Other pre render template profile...
                # js     =&gt; { ... },
                # jquery =&gt; { ... },
                
            },

            TT =&gt; {
                object   =&gt; Template-&gt;new( INCLUDE_PATH =&gt; './tt' ),
                postfix  =&gt; '.tt',
                site_tit =&gt; 'Static CSS demo',
            },
        );
    }
    
    # static file handling
    sub continue {
        my $app = shift;
        $app-&gt;next::method(
            docroot =&gt; $CSS::CONFIG{ docroot },
            staticp =&gt; sub { 
                $_[0]-&gt;url =~ m/\.(jpg|jpeg|gif|png|css|ico|js|swf)$/ 
            },
            @_
        );
    }
    
    # pre-render stuff
    # for eg. lets build the CSS file on startup as ./www/static/static.css
    my $tt = $CSS::CONFIG{ TT }-&gt;{ object };
    my $prefix = $CSS::CONFIG{ docroot } . $CSS::CONFIG{ static } . '/';
    for my $key ( keys %{  $CSS::CONFIG{ pre_render } } ) {
        
        my $render = $CSS::CONFIG{ pre_render }-&gt;{ $key };
        
        open my $fh, '&gt;',  $prefix . $render-&gt;{ file }
            or die &quot;Unable to write to $render-&gt;{file}: $!&quot;;

        $tt-&gt;process( $render-&gt;{ tt }, $render-&gt;{ v }, $fh )
            or die &quot;Help!\n&quot;;

        close $fh;   
    }

}


{ 
    package CSS::Controllers;
    use Squatting ':controllers';
    
    our @C = (
        C(
            Home =&gt; [ '/' ],
            get   =&gt; sub { 
                my ( $self ) = @_;
                $self-&gt;render( 'home' );
            },
        ),
    );
}


{
    package CSS::Views;
    use Squatting ':views';

    our @V = (

        V(
            'tt',
            tt =&gt; $CSS::CONFIG{ TT }-&gt;{ object },

            layout =&gt; sub {
                my ( $self, $v, $body ) = @_;
                my $tt = $self-&gt;{ tt };
                $v-&gt;{ site_tit } = $CSS::CONFIG{ TT }-&gt;{ site_tit };
                $v-&gt;{ body     } = $body;

                my $output;
                $tt-&gt;process( 'layout'. $CSS::CONFIG{ TT }-&gt;{ postfix }, 
                               $v, \$output)
                    or return view_error( $tt-&gt;error );
                return $output;
            },

            _ =&gt; sub {
                my ( $self, $v ) = @_;
                my $tt = $self-&gt;{ tt };
                $v-&gt;{ R } = \&amp;R;
                $v-&gt;{ Static } = $CSS::CONFIG{ static };

                my $output;
                $tt-&gt;process( $self-&gt;{template} . 
                              $CSS::CONFIG{ TT }-&gt;{ postfix }, 
                              $v, \$output) 
                    or return view_error( $tt-&gt;error );
                return $output;
            },
        ),
    );

    sub view_error {
        my ( $error ) = shift;
        warn $error;
        return &quot;&lt;pre&gt;&quot; . $error . &quot;&lt;/pre&gt;\n&quot;;   # should HTML encode
    }    
}

1;
</pre></p>
<p>$CSS::CONFIG{ pre_render } contains all the profiles to pre-render on.   You just need to name a profile and tell it what template (tt), what static filename should be (file) &amp; provide variables for the rendering (v)&#8230;.</p>
<p><pre class="brush: perl;">
        # CSS profile
        css =&gt; {
            tt   =&gt; 'css.tt',         # CSS template 
            file =&gt; 'static.css',    # Name of static file to build
            v    =&gt; {                 # template variables
                colour =&gt; 'red',
            },
        },
</pre></p>
<p>So above renders css.tt to ./www/static/static.css</p>
<p>Here is an example css.tt<br />
<pre class="brush: css;">
h1 { color: [% colour %]; }
</pre></p>
<p>And to make things complete here the other templates (all in ./tt folder)&#8230;.</p>
<p><pre class="brush: xml;">
# layout.tt
&lt;html&gt;
&lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
  &lt;title&gt;[% site_tit %]&lt;/title&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;[% Static %]/static.css&quot; type=&quot;text/css&quot; /&gt;
&lt;/head&gt;

&lt;body&gt;
[% body %]
&lt;/body&gt;
&lt;/html&gt;

# home.tt
&lt;h1&gt;This should be red&lt;/h1&gt;
</pre></p>
<p>And if all works fine then you will see &#8220;This should be red&#8221; in red <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>/I3az/</p>
<p>NB. This example should only be used with single occurrence of your App running with Squatting::On::Continuity.   For multiple occurrences then ideally you need to take care when writing to static file (ie. only write when changed or need locking or have unique static files for each occurrence).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/draegtun.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/draegtun.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/draegtun.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/draegtun.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/120/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/120/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/120/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=120&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2008/12/23/pre-render-template-at-squatting-start-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>CSS views in Squatting</title>
		<link>http://transfixedbutnotdead.com/2008/12/23/css-views-in-squatting/</link>
		<comments>http://transfixedbutnotdead.com/2008/12/23/css-views-in-squatting/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 16:43:04 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Squatting]]></category>
		<category><![CDATA[Template Toolkit]]></category>

		<guid isPermaLink="false">http://draegtun.wordpress.com/?p=105</guid>
		<description><![CDATA[From my earlier post today you will probably have noticed a problem with CSS files when something like following is used&#8230;. What we want this to be is otherwise it won&#8217;t find that image file in your static folder&#8230; This means we need to process a CSS template through a Squatting view (see Caveat). Here&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=105&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>From my <a href="http://draegtun.wordpress.com/2008/12/23/using-squatting-with-reverse-proxy-apache/">earlier post</a> today you will probably have noticed a problem with CSS files when something like following is used&#8230;.</p>
<p><pre class="brush: css;">
body {
	background: url( /images/some_image.gif );
}
</pre></p>
<p>What we want this to be is otherwise it won&#8217;t find that image file in your static folder&#8230;</p>
<p><pre class="brush: css;">
body {
	background: url( [% Static %]/images/some_image.gif );
}
</pre></p>
<p>This means we need to process a CSS template through a Squatting view (see Caveat).</p>
<p>Here&#8217;s one way we can do this&#8230;..</p>
<p><pre class="brush: perl;">

# Controller code.....
    C( 
        CSS =&gt; [ '/css' ],
        get =&gt; sub { 
            my $self = shift; 
            $self-&gt;headers-&gt;{'Content-Type'} = 'text/css'; 
            $self-&gt;render( '_app_css' );
        },
    ),
</pre></p>
<p>&#8220;_app_css.tt&#8221; is now your CSS template.  The prefixed &#8220;_&#8221; in the $self-&gt;render stops it processing the layout view around it.  The layout.tt should now have this line&#8230;</p>
<p><pre class="brush: xml;">
    &lt;link rel=&quot;stylesheet&quot; href=&quot;[% R('CSS') %]&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;Demo&quot; /&gt;
</pre></p>
<p>So when rendered to browser the HTML will look like this&#8230;..</p>
<p><pre class="brush: xml;">
    &lt;link rel=&quot;stylesheet&quot; href=&quot;/css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;Demo&quot; /&gt;
</pre></p>
<p>So &#8220;/css&#8221; will call the CSS controller and render the template &#8220;_app_css.tt&#8221;.</p>
<p>And so Bob&#8217;s your Aunty <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>/I3az/</p>
<p><em>Caveat</em>: And its a big caveat&#8230;.  while its nice and could be very useful in lots of cases to serve up dynamic CSS, it is generally going to be a lot better to keep it as a static file and let Apache serve it up and gain all the cache benefits associated with this.</p>
<p>Two possible workarounds are&#8230;.</p>
<ul>
<li>Build static file from TT file.  This could even be done when Squatting app is first started.  Alternatively look at TT tpage &amp; ttree to do this process manually
<li>Put caching routines into your CSS View (eg. pre-build rendering, return 304 HTTP code).
</ul>
<p><em>NB.</em>: Replace CSS with Javascript in everything above.   Everything equally applies.</p>
<p>References</p>
<ul>
<li><a href="http://draegtun.wordpress.com/2008/10/21/using-template-toolkit-with-squatting/">Using Template Toolkit With Squatting</a>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/draegtun.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/draegtun.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/draegtun.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/draegtun.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=105&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2008/12/23/css-views-in-squatting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Squatting with reverse proxy (Apache)</title>
		<link>http://transfixedbutnotdead.com/2008/12/23/using-squatting-with-reverse-proxy-apache/</link>
		<comments>http://transfixedbutnotdead.com/2008/12/23/using-squatting-with-reverse-proxy-apache/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 15:18:50 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[reverse proxy]]></category>
		<category><![CDATA[Squatting]]></category>

		<guid isPermaLink="false">http://draegtun.wordpress.com/?p=75</guid>
		<description><![CDATA[OK so you&#8217;ve just developed your first Squatting (On::Continuity) app and you now want to put it live on your main website/webserver.   So how do you do this? Well a good seamless &#38; scalable choice is using a Reverse Proxy.   This allows us to map a URL straight to a running Squatting app without [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=75&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>OK so you&#8217;ve just developed your first Squatting (On::Continuity) app and you now want to put it live on your main website/webserver.   So how do you do this?</p>
<p>Well a good seamless &amp; scalable choice is using a <a href="http://http://en.wikipedia.org/wiki/Reverse_proxy">Reverse Proxy</a>.   This allows us to map a URL straight to a running Squatting app without too much fuss (famous last words!)</p>
<p>For this exercise I&#8217;ve used Apache (2.2) and with a bit trail &amp; error I got below to work for me.</p>
<p>First off we need to switch on reverse proxy.   You will need to following in your httpd.conf file&#8230;.</p>
<pre>
    ProxyRequests Off

    &lt;Proxy *&gt;
        Order deny,allow
        Allow from all
    &lt;/Proxy&gt;
</pre>
<p>Now we want to make it point to our Squatting app&#8230;.</p>
<pre>
    &lt;VirtualHost *:80&gt;
      DocumentRoot "/var/www/vhosts/www.mysite.com/html"
      ServerName www.mysite.com

      ProxyPass /demo/ http://localhost:4234/demo/
      ProxyPassReverse /demo/ http://localhost:4234/demo/
    &lt;/VirtualHost&gt;
</pre>
<p>Now any requests to www.mysite.com/demo/ are &#8220;forwarded&#8221; on to your Squatting app running on port 4234.</p>
<p>You may notice that I put a trailing /demo/ on the proxy.  This is because the Squatting app is launched via this script&#8230;.</p>
<p><pre class="brush: perl;">
#!/usr/bin/env perl

use Demo 'On::Continuity', 'With::AccessTrace';
Demo-&gt;init;
Demo-&gt;relocate( '/demo' );
Demo-&gt;continue(port =&gt; 4234);
</pre></p>
<p>I found this helped the webserver map back to the proxy when requests were made by the browser (eg.  www.mysite.com/demo/login).  I&#8217;m sure there must be another (better?) way but this did work best for me despite endless fiddling with ProxyPass* &amp; RewriteRules ;-(</p>
<p>Restart Apache &amp; start above script in your Squatting app directory and you should find it is now accessible at www.mysite.com/demo/.   That is except for any static content u had ;-(</p>
<p>Apache is better suited for pushing out static content so its best to let it deal with this by putting static files somewhere under its document root.   However this did present a &#8220;best practise&#8221; problem between Continuity serving static files during testing and going live with Apache.</p>
<p>My approach to this was to prefix all static URI with &#8220;demohtml&#8221; using following code in Demo.pm</p>
<p><pre class="brush: perl;">
package Demo;
use strict;
use warnings;
use base 'Squatting';

BEGIN {
    our %CONFIG = (

        static =&gt; '/demohtml',
        
        TT =&gt; {
            config   =&gt; { INCLUDE_PATH =&gt; './tt' },
            postfix  =&gt; '.tt',
            site_tit =&gt; 'Demo',
        }
    );

}

use Demo::Controllers;
use Demo::Views;

# static file handling
sub continue {
    my $app = shift;
    $app-&gt;next::method(
        docroot =&gt; &quot;./www&quot;, 
        staticp =&gt; sub { 
            $_[0]-&gt;url =~ m/\.(jpg|jpeg|gif|png|css|ico|js|swf)$/ 
        },
        @_
    );
}

1;
</pre></p>
<p>Then I would have the following in my View &amp; template(s)&#8230;..</p>
<p><pre class="brush: perl;">

# in Demo::Views (good place is in &quot;_&quot; default template)
$v-&gt;{ Static } = $Demo::CONFIG{ static };

# and then in TT file(s)....
&lt;link rel=&quot;stylesheet&quot; href=&quot;[% Static %]/demo.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;Demo&quot; /&gt;
</pre></p>
<p>Therefore the above now appears in the HTML like so&#8230;</p>
<pre>
    &lt;link rel="stylesheet" href="/demohtml/demo.css" type="text/css" media="screen" title="Demo" /&gt;</pre>
<p>This Demo&#8217;s static content lives under ./www/demohtml/ in the Squatting app directory so works fine with Continuity during testing.  I then sym-linked ./www/demohtml under the Apache document root so that u can see it @ www.mysite.com/demohtml/ </p>
<p>So Bob&#8217;s your Uncle&#8230; u should now find your Squatting app working via reverse proxy as u would expect it to <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>/I3az/</p>
<p>Further reading&#8230;   Have a look at <a href="http://search.cpan.org/dist/App-VW/">App::VW</a> to manage the Squatting apps.</p>
<p>References&#8230;</p>
<ul>
<li><a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html">Apache 2.2 mod_proxy docs</a>
<li><a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">Apache 2.2 mod_rewrite docs</a>
<li><a href="http://www.apachetutor.org/admin/reverseproxies">Running a Reverse Proxy in Apache</a>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/draegtun.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/draegtun.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/draegtun.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/draegtun.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=75&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2008/12/23/using-squatting-with-reverse-proxy-apache/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Template Toolkit with Squatting</title>
		<link>http://transfixedbutnotdead.com/2008/10/21/using-template-toolkit-with-squatting/</link>
		<comments>http://transfixedbutnotdead.com/2008/10/21/using-template-toolkit-with-squatting/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 12:04:53 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Camping]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Squatting]]></category>
		<category><![CDATA[Template Toolkit]]></category>

		<guid isPermaLink="false">http://draegtun.wordpress.com/?p=45</guid>
		<description><![CDATA[Been playing with Squatting recently. Its a Perl Web microframework inspired by Camping. For someone like me who is still converting some old CGI apps to Catalyst then this looks like an interesting alternative. I use Template Toolkit quite a bit so here&#8217;s a boilerplate for using TT with Squatting&#8230;.. And here are the templates&#8230;. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=45&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Been playing with <a href="http://search.cpan.org/dist/Squatting/">Squatting</a> recently.   Its a Perl Web microframework inspired by <a href="http://code.whytheluckystiff.net/camping">Camping</a>.  For someone like me who is still converting some old CGI apps to Catalyst then this looks like an interesting alternative.</p>
<p>I use Template Toolkit quite a bit so here&#8217;s a boilerplate for using TT with Squatting&#8230;..</p>
<p><pre class="brush: perl;">
use strict;
use warnings;

{
    package App;
    use base 'Squatting';

    BEGIN {
        our %CONFIG = (
            TT =&gt; {
                config   =&gt; { INCLUDE_PATH =&gt; '.' },
                postfix  =&gt; '.tt',
                site_tit =&gt; 'TT loves Squatting!',
            }
        );

    }
}

{
    package App::Controllers;
    use Squatting ':controllers';

    our @C = (

        C(
            Home =&gt; [ '/' ],
            get  =&gt; sub {
                my ( $self )  = @_;
                my $v         = $self-&gt;v;
                $v-&gt;{ tit }   = 'welcome to my homepage';
                $self-&gt;render( 'home' );
            },
        ),
        
        C(
            Page =&gt; [ '/path/to/page' ],
            get  =&gt; sub {
                my ( $self ) = @_;
                my $v        = $self-&gt;v;
                $v-&gt;{ tit  } = 'here is another page!';
                $v-&gt;{ list } = [ 'one', 'two', 'three' ];
                $self-&gt;render( 'page' );
            },
        ),

    );
}

{
    package App::Views;
    use Squatting ':views';
    use Template;

    our @V = (

        V(
            'html',
            tt =&gt; Template-&gt;new( $App::CONFIG{ TT }-&gt;{ config } ),

            layout =&gt; sub {
                my ( $self, $v, $body ) = @_;
                my $tt = $self-&gt;{ tt };
                $v-&gt;{ site_tit } = $App::CONFIG{ TT }-&gt;{ site_tit };
                $v-&gt;{ body     } = $body;
                
                my $output;
                $tt-&gt;process( 'layout'. $App::CONFIG{ TT }-&gt;{ postfix }, $v, \$output)
                    or return view_error( $tt-&gt;error );
                return $output;
            },

            _ =&gt; sub {
                my ( $self, $v ) = @_;
                my $tt = $self-&gt;{ tt };
                $v-&gt;{ R } = \&amp;R;
                
                my $output;
                $tt-&gt;process( $self-&gt;{template} . $App::CONFIG{ TT }-&gt;{ postfix }, $v, \$output) 
                    or return view_error( $tt-&gt;error );
                return $output;
            }

        ),
    );
    
    sub view_error {
        my ( $error ) = shift;
        warn $error;
        return &quot;&lt;pre&gt;&quot; . $error . &quot;&lt;/pre&gt;\n&quot;;   # really need to HTML encode $error here
    }
}

1;
</pre></p>
<p>And here are the templates&#8230;.</p>
<p>layout.tt<br />
<pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;
   &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;

&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
	&lt;title&gt;[% site_tit %]&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
[% body %]
&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p>home.tt<br />
<pre class="brush: xml;">
&lt;h1&gt;Hello.. [% tit %]&lt;/h1&gt;

&lt;a href=&quot;[% R('Page') %]&quot;&gt;Have a look here&lt;/a&gt;
</pre></p>
<p>page.tt<br />
<pre class="brush: xml;">
&lt;h1&gt;Hello again... [% tit %]&lt;/h1&gt;

&lt;p&gt;$v-&gt;{list}...&lt;/p&gt;

&lt;ul&gt;
    [% FOREACH item IN list %]
    &lt;li&gt;[% item %]&lt;/li&gt;
    [% END %]
&lt;/ul&gt;

&lt;a href=&quot;[% R('Home') %]&quot;&gt;back to home&lt;/a&gt;
</pre></p>
<p>Stash variables in Squatting (ie. variables that can used between controller &amp; the view/template) can be set/get by $self-&gt;v<br />
<em>NB. &#8220;v&#8221; is for variables and shouldn&#8217;t be confused in anyway with &#8220;view&#8221; ;-(</em></p>
<p>Using &#8220;layout[.tt]&#8221; method/template is optional in Squatting (and Camping) so u can drop this and it will just render the view/template only.  The code uses &#8220;layout&#8221; thus home.tt &amp; page.tt renders as [% body %] via layout.tt</p>
<p>R() returns the route used by the specified controller ( for eg. R(&#8216;Page&#8217;) returns &#8220;/path/to/page&#8221; ).  This is quite a handy subroutine to export to TT templates!</p>
<p>So see it working just name above program &#8220;App.pm&#8221; and put in same directory as the template files and just do <code>squatting App</code> and then point your browser to http://localhost:4234/</p>
<p>Hopefully more on Squatting soon.  So if u fancy a bit of fun web programming then give Squatting a go!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/draegtun.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/draegtun.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/draegtun.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/draegtun.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&amp;blog=351142&amp;post=45&amp;subd=draegtun&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2008/10/21/using-template-toolkit-with-squatting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/29cb106071d163d703484e63839d89cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">draegtun</media:title>
		</media:content>
	</item>
	</channel>
</rss>
