<?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; perl</title>
	<atom:link href="http://transfixedbutnotdead.com/tag/perl/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>Thu, 04 Feb 2010 09:04:10 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='transfixedbutnotdead.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/0a317653027efb1ab2bf8adde3dcb067?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>transfixed but not dead! &#187; perl</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!" />
		<item>
		<title>Perl and Mac OS X versions</title>
		<link>http://transfixedbutnotdead.com/2010/02/03/perl-and-mac-os-x-versions/</link>
		<comments>http://transfixedbutnotdead.com/2010/02/03/perl-and-mac-os-x-versions/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 10:42:05 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Mac OSX]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=836</guid>
		<description><![CDATA[Apple website has an opensource page: http://www.opensource.apple.com/, which lists all its products and components which have and use opensource technology.
If you go here: http://www.apple.com/opensource/, it provides a complete list of opensource projects that Apple uses.  
In this list is of course Perl.  From this we can see which version of Perl was compiled [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=836&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Apple website has an opensource page: <a href="http://www.opensource.apple.com/">http://www.opensource.apple.com/</a>, which lists all its products and components which have and use opensource technology.</p>
<p>If you go here: <a href="http://www.apple.com/opensource/">http://www.apple.com/opensource/</a>, it provides a complete list of opensource projects that Apple uses.  </p>
<p>In this list is of course <a href="http://www.opensource.apple.com/source/perl/">Perl</a>.  From this we can see which version of Perl was compiled on Mac OS X.  We can also see what options, patches, fixes &amp; extra modules were included.</p>
<p>So I&#8217;ve been able to glean these Perl versions that Apple have used with Mac OS X:</p>
<ul>
<li>5.10.0 &amp; 5.8.9		(perl-63)</li>
<li>5.8.8				(perl-51 patches: perl-51.1.1, perl-51.1.4)</li>
<li>5.8.6				(perl-38 patch: perl-38.1)	</li>
<li>5.8.6	(perl-35 patch: perl-35.1.1)</li>
<li>5.8.4	(perl-28.2)</li>
<li>5.8.1-RC3	(perl-25.2)</li>
<li>5.8.1	(perl-24.1)	&#8220;Maintenance release working toward v5.8.1&#8243;</li>
<li>5.6.0	(perl-21)</li>
<li>5.6.0	(perl-17)</li>
</ul>
<p>Now which one(s) are tied to which Mac OS X is still in the air a bit!  This is my best stab at it:</p>
<pre>
  10.6    5.10.0 &amp; 5.8.9      perl-63
  10.5    5.8.8               perl-51
  10.4    5.8.6               perl-38 or perl-35
  10.3    5.8.4 or 5.8.1 ?
  10.2    5.8.1 ?
  10.1    5.6.0               ? perl-21 and/or perl-17
  10.0    5.6.0 ?
</pre>
<p>Hopefully this information is <a href="http://stackoverflow.com/questions/2092944/how-can-i-find-out-which-perl-version-was-available-on-older-mac-os-x-versions">useful to someone</a></p>
<p>/I3az/</p>
<p>refs: </p>
<ul>
<li><a href="http://transfixedbutnotdead.com/2010/01/24/mac-os-x-snow-leopard-10-6-and-perl/">Mac OS X “Snow Leopard” (10.6) and Perl</a></li>
<li><a href="http://news.ycombinator.com/item?id=1095075">Apple Open Source (Hacker News)</a>
<li>
</ul>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/836/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/836/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/836/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/836/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/836/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/836/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/836/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/836/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/836/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/836/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=836&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/02/03/perl-and-mac-os-x-versions/feed/</wfw:commentRss>
		<slash:comments>2</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>Mac OS X &#8220;Snow Leopard&#8221; (10.6) and Perl</title>
		<link>http://transfixedbutnotdead.com/2010/01/24/mac-os-x-snow-leopard-10-6-and-perl/</link>
		<comments>http://transfixedbutnotdead.com/2010/01/24/mac-os-x-snow-leopard-10-6-and-perl/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 16:38:27 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Mac OSX]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perl 5.10]]></category>
		<category><![CDATA[Snow Leopard]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=831</guid>
		<description><![CDATA[Snow Leopard ships with multiple versions of Perl:

5.10.0 (64 bit)
5.10.0 (32 bit)
5.8.9  (32 bit)

The default Perl is 5.10.0 (64 bit).   However you can change this to 32-bit Perl by setting the following ENV shell variable:
export VERSIONER_PERL_PREFER_32_BIT=yes
And to switch to 5.8.9 all you need is this ENV variable set:
export VERSIONER_PERL_VERSION=5.8.9
Instead of setting these [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=831&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Snow Leopard ships with multiple versions of Perl:</p>
<ul>
<li>5.10.0 (64 bit)
<li>5.10.0 (32 bit)
<li>5.8.9  (32 bit)
</ul>
<p>The default Perl is 5.10.0 (64 bit).   However you can change this to 32-bit Perl by setting the following ENV shell variable:</p>
<p><code>export VERSIONER_PERL_PREFER_32_BIT=yes</code></p>
<p>And to switch to 5.8.9 all you need is this ENV variable set:</p>
<p><code>export VERSIONER_PERL_VERSION=5.8.9</code></p>
<p>Instead of setting these ENV variables in your Terminal sessions you can also make the change to the systems defaults:</p>
<ul>
<li>defaults write com.apple.versioner.perl Prefer-32-Bit -bool yes
<li>defaults write com.apple.versioner.perl Version 5.8.9
</ul>
<p>This is a interesting move by Apple and something which may come in very handy in the future.</p>
<p>As it stands at this moment though you probably want 5.10.1 (and beyond) because of issues with 5.10.0.  So you will probably be looking down the compiling route anyway.  Still it does give the future option of a <a href="http://search.cpan.org/dist/local-lib/">local::lib</a> possibility with the pre-installed Perl provided by Apple.</p>
<p><em>NB. I always recommend that you avoid installing modules with CPAN (shell) on OS provided Perl.  Always stick to the OS provided package installer to update Perl &amp; modules (which unfortunately for Mac&#8217;s means &#8220;zilch&#8221; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   Apple &#8220;Software Updater&#8221; may update Perl itself but no extra modules are provided above what Apple provides on top of core Perl)</em></p>
<p>/I3az/</p>
<p>References:</p>
<ul>
<li><a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/perlmacosx5.10.0.1.html">README.macosx &#8211; Perl under Mac OS X</a>
<li><a href="http://use.perl.org/~pudge/journal/39596">Mac-Carbon Modules and Mac OS X 10.6</a>
<li><a href="http://daringfireball.net/2009/09/snow_leopard_applescript_perl_safari_webkit">Snow Leopard Compatibility Tweaks for That Thing I Wrote in January About Writing AppleScripts That Dynamically Target Either Safari or WebKit</a>
<li><a href="http://stackoverflow.com/questions/2092944/how-can-i-find-out-which-perl-version-was-available-on-older-mac-os-x-versions/2093325#2093325">How can I find out which Perl version was available on older Mac OS X versions?</a>
</ul>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/831/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=831&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/01/24/mac-os-x-snow-leopard-10-6-and-perl/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>
		<item>
		<title>Anyone for Perl 6 metaprogramming?</title>
		<link>http://transfixedbutnotdead.com/2010/01/14/anyone-for-perl-6-metaprogramming/</link>
		<comments>http://transfixedbutnotdead.com/2010/01/14/anyone-for-perl-6-metaprogramming/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 22:11:36 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[metaprogramming]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perl6]]></category>
		<category><![CDATA[rakudo]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=823</guid>
		<description><![CDATA[My last post about the Metaprogramming: Ruby vs. Javascript blog post stirred a little thought in my head:
How would it look in Perl 6?
Well here goes, the complete example written in Perl 6 which runs on Rakudo, an implementation of the Perl 6 spec on the Parrot VM:

use v6;

class Ninja {
    has [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=823&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>My <a href="http://transfixedbutnotdead.com/2010/01/13/anyone_for_metaprogramming/">last post</a> about the <a href="http://fingernailsinoatmeal.com/post/292301859/metaprogramming-ruby-vs-javascript">Metaprogramming: Ruby vs. Javascript</a> blog post stirred a little thought in my head:</p>
<blockquote><p>How would it look in Perl 6?</p></blockquote>
<p>Well here goes, the complete example written in <a href="http://en.wikipedia.org/wiki/Perl_6">Perl 6</a> which runs on <a href="http://www.rakudo.org/">Rakudo</a>, an implementation of the Perl 6 spec on the <a href="http://en.wikipedia.org/wiki/Parrot_virtual_machine">Parrot VM</a>:</p>
<pre class="brush: perl;">
use v6;

class Ninja {
    has Str $.name is rw;
}

my Ninja $drew .= new( name =&gt; 'Drew' );
my Ninja $adam .= new( name =&gt; 'Adam' );

###########################################################
# Reopen Ninja class (&quot;is also&quot; does the biz)
# and add 'battle_cry' method

class Ninja is also {
    method battle_cry {
        say $.name ~ ' says zing!!!';
    }
}

$drew.battle_cry;   # =&gt; Drew says zing!!!
$adam.battle_cry;   # =&gt; Adam says zing!!!

###########################################################
# add 'throw_star' method to $drew object by creating
# and applying (&quot;does&quot;) role to it (Singleton method)

role ThrowStar {
    method throw_star { say &quot;throwing star&quot; }
}

$drew does ThrowStar;
$drew.throw_star;     # =&gt; throwing a star

###########################################################
# call method dynamically: $obj.'method_name' or $obj.$method

$drew.'battle_cry';     # =&gt; Drew says zing!!!

###########################################################
# add &quot;colour&quot; method closing over $colour_name (ie. closure):

my $colour_name = 'black';

class Ninja is also {
    method colour { say &quot;{$.name}'s colour is {$colour_name} &quot; }
}

$drew.colour;    # =&gt; Drew's colour is black
$adam.colour;    # =&gt; Adam's colour is black

###########################################################

# &quot;defining a method dynamically on an instance that closes
# over local scope and accesses the instance’s state&quot;

my $sword_symbol = '********';

$drew.^add_method( 'swing', method ( Str $sound_effect ) {
    say &quot;{$.name}: {$sword_symbol} {$sound_effect}&quot;;
});

$drew.swing( 'slash!!' );    # =&gt; Drew: ********* slash!!
</pre>
<p>Of all the examples (in Perl 5 / Moose, Ruby, Javascript &amp; <a href="http://codeblog.dhananjaynene.com/2010/01/dynamically-adding-methods-with-metaprogramming-ruby-and-python/">Python</a>) I think this one is the most clean and intuitive.  Perl 6 has a good future if it keeps this up!</p>
<p>And it all went surprising smoothly.  There were a couple of bumps in my Perl 6 road but these are all connected to the flux between the Perl 6 spec, Rakudo and knowing what info you find on the web is still accurate (or not). </p>
<p>First bump was how to re-open a class.  Most Perl 6 documentation implied that classes were always open (unless <code>is final</code> was used).  This no longer seemed to be the case and it gave examples of <code>class A is augmented { ... }</code>.  However this didn&#8217;t work in Rakudo but eventually I came across <code>is also</code> which did.</p>
<p>I like the look of <code>class A is also { ... }</code>.  However <a href="http://perlgeek.de/en/">Moritz</a> on IRC #perl6 mentioned that the Perl 6 spec had changed so my example would need to be:</p>
<pre class="brush: perl;">
augment class Ninja {
    method battle_cry {
        say $.name ~ ' says zing!!!';
    }
}
</pre>
<p>Rakudo is currently a bit behind Perl 6 spec here but above will replace <code>is also</code> shortly.  The change to <em>augment</em> makes sense because it avoids any confusion with roles in the class declaration.</p>
<p>The second bump was how to create a method dynamically.  Now being familiar with Moose I had expected the following to work:</p>
<pre class="brush: perl;">
Ninja.meta.add_method( 'swing', method ( Str $sound_effect ) {
    say &quot;{$.name}: {$sword_symbol} {$sound_effect}&quot;;
});
</pre>
<p>And according to most Perl 6 docs <code>.meta</code> was the method to access the metaclass (MOP).  However <em>meta</em> produced a method not defined error <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Trawling the web further I did find that you could do:</p>
<pre class="brush: perl;">
Ninja.swing = method { say &quot;Changed to zing&quot; };
</pre>
<p>But this only allowed you to redefine a method, not create a new one.</p>
<p>Luckily IRC #perl6 came to the rescue again!  <a href="http://github.com/jnthn">jnthn</a> &amp; Moritz pointed me to <code>$object.^add_method( ... )</code> and the <a href="http://github.com/rakudo/rakudo/blob/ng/docs/metamodel.pod#">docs on the ng branch</a> of <a href="http://github.com/rakudo/rakudo">Rakudo</a> on Github.</p>
<p>Perl6 does have some beautiful syntax.  I love the <code>$drew does Throwstar</code> line.  Soon Rakudo will be able to do:</p>
<pre class="brush: perl;">
$drew does role {
    method throw_star { say &quot;throwing star&quot; }
};
</pre>
<p>So this, <em>augment</em> and probably lots more will be part of the <a href="http://github.com/rakudo/rakudo/tree/ng">ng branch</a> which will be merged with the Rakudo master in the not too distant future.</p>
<p>/I3az/</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/823/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/823/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/823/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=823&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/01/14/anyone-for-perl-6-metaprogramming/feed/</wfw:commentRss>
		<slash:comments>4</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>Anyone for metaprogramming?</title>
		<link>http://transfixedbutnotdead.com/2010/01/13/anyone_for_metaprogramming/</link>
		<comments>http://transfixedbutnotdead.com/2010/01/13/anyone_for_metaprogramming/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 14:41:43 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[metaprogramming]]></category>
		<category><![CDATA[moose]]></category>
		<category><![CDATA[MooseX::Declare]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[singleton methods]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=813</guid>
		<description><![CDATA[What is metaprogramming? Well this question caused a heated discussion on Hacker News yesterday.
I personally would describe that metaprogramming provides the ability to:
transform programs with programs
and leave it at that!
The article that stirred the metaprogramming pot was Metaprogramming: Ruby vs. Javascript. This actually is a good post and it helped fill in a few holes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=813&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>What is metaprogramming? Well this question caused a <a href="http://news.ycombinator.com/item?id=1047616">heated discussion</a> on <a href="http://news.ycombinator.com/news">Hacker News</a> yesterday.</p>
<p>I personally would describe that <a href="http://en.wikipedia.org/wiki/Metaprogramming">metaprogramming</a> provides the ability to:</p>
<blockquote><p>transform programs with programs</p></blockquote>
<p>and leave it at that!</p>
<p>The article that stirred the metaprogramming pot was <a href="http://fingernailsinoatmeal.com/post/292301859/metaprogramming-ruby-vs-javascript">Metaprogramming: Ruby vs. Javascript</a>. This actually is a good post and it helped fill in a few holes in my &#8220;fragile&#8221; Javascript knowledge.</p>
<p>Luckily I believe my Perl is a bit less fragile!, so I thought I would convert the metaprogramming examples into Perl &amp; <a href="http://moose.perl.org">Moose</a>.</p>
<p>So following the blogs examples, below defines the Ninja class in Moose. <a href="http://search.cpan.org/dist/MooseX-SingletonMethod/">MooseX::SingletonMethod</a> loads Moose with a bit of <a href="http://transfixedbutnotdead.com/2009/07/15/moosexsingletonmethod-now-on-cpan/">singleton method sugar</a>.</p>
<pre class="brush: perl;">
use Modern::Perl;

{
    package Ninja;
    use MooseX::SingletonMethod;
    use namespace::clean -except =&gt; 'meta';

    has name =&gt; ( is =&gt; 'rw', isa =&gt; 'Str' );
}

my $drew = Ninja-&gt;new( name =&gt; 'Drew' );
my $adam = Ninja-&gt;new( name =&gt; 'Adam' );
</pre>
<p><em>NB. namespace::clean stops the Moose sugar percolating into Ninja class (except meta&#8230; which is the Meta Object Protocol method&#8230; which handy for metaprogramming!).</em></p>
<p>Now we re-open the Ninja class and add <code>battle_cry</code> method like so:</p>
<pre class="brush: perl;">
{
    package Ninja;

    sub battle_cry {
        my $self = shift;
        say $self-&gt;name . ' says zing!!!';
    }
}

$drew-&gt;battle_cry;   # =&gt; Drew says zing!!!
$adam-&gt;battle_cry;   # =&gt; Adam says zing!!!
</pre>
<p>Now using MooseX::SingletonMethod we add <code>throw_star</code> singleton method into $drew object:</p>
<pre class="brush: perl;">
$drew-&gt;add_singleton_method( throw_star =&gt; sub {
    say &quot;throwing star&quot;;
});

$drew-&gt;throw_star;   # =&gt; throwing a star
</pre>
<p>To call method dynamically we do this:</p>
<pre class="brush: perl;">
$drew-&gt;${ \'battle_cry' };   # =&gt; Drew says zing!!!
</pre>
<p>Create <code>colour</code> method closing over $colour_name (ie. closure):</p>
<pre class="brush: perl;">
my $colour_name = 'black';

Ninja-&gt;meta-&gt;add_method( colour =&gt; sub {
    my $self = shift;
    say &quot;${ \$self-&gt;name }'s colour is $colour_name&quot;;
});

$drew-&gt;colour;    # =&gt; Drew's colour is black
$adam-&gt;colour;    # =&gt; Adam's colour is black
</pre>
<p>Finally&#8230; <em>&#8220;defining a method dynamically on an instance that closes over local scope and accesses the instance’s state&#8221;</em></p>
<pre class="brush: perl;">
my $sword_symbol = '********';

$drew-&gt;add_singleton_method( swing =&gt; sub {
    my ($self, $sound_effect) = @_;
    say &quot;${ \$self-&gt;name }: $sword_symbol $sound_effect&quot;;
});

$drew-&gt;swing( 'slash!!' );   # =&gt; Drew: ********* slash!!
</pre>
<p>Everything nicely works the same as the Ruby &amp; Javascript blog examples.</p>
<p>To round things off, below is the complete example but with <a href="http://search.cpan.org/dist/MooseX-Declare/">MooseX::Declare</a> sugar stirred into the pot.</p>
<pre class="brush: perl;">
use Modern::Perl;
use MooseX::Declare;

class Ninja with MooseX::SingletonMethod::Role is mutable {
    has name =&gt; ( is =&gt; 'rw', isa =&gt; 'Str' );
}

my $drew = Ninja-&gt;new( name =&gt; 'Drew' );
my $adam = Ninja-&gt;new( name =&gt; 'Adam' );

###########################################################

class Ninja is mutable {
    method battle_cry {
        say $self-&gt;name . ' says zing!!!';
    }
}

$drew-&gt;battle_cry;   # =&gt; Drew says zing!!!
$adam-&gt;battle_cry;   # =&gt; Adam says zing!!!

###########################################################

$drew-&gt;add_singleton_method( throw_star =&gt; sub {
    say &quot;throwing star&quot;;
});

$drew-&gt;throw_star;   # =&gt; throwing a star

###########################################################

$drew-&gt;${ \'battle_cry' };   # =&gt; Drew says zing!!!

###########################################################

my $colour_name = 'black';

Ninja-&gt;meta-&gt;add_method( colour =&gt; sub {
    my $self = shift;
    say &quot;${ \$self-&gt;name }'s colour is $colour_name&quot;;
});

$drew-&gt;colour;    # =&gt; Drew's colour is black
$adam-&gt;colour;    # =&gt; Adam's colour is black

###########################################################

my $sword_symbol = '********';

$drew-&gt;add_singleton_method( swing =&gt; sub {
    my ($self, $sound_effect) = @_;
    say &quot;${ \$self-&gt;name }: $sword_symbol $sound_effect&quot;;
});

$drew-&gt;swing( 'slash!!' );   # =&gt; Drew: ********* slash!!
</pre>
<p>/I3az/</p>
<p>PS.  If you want Moose in Javascript then have a look at <a href="http://code.google.com/p/joose-js/">Joose</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/813/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/813/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/813/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/813/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/813/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/813/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=813&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/01/13/anyone_for_metaprogramming/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>Receiving contributions to your Github project</title>
		<link>http://transfixedbutnotdead.com/2010/01/04/receiving-contributions-to-your-github-project/</link>
		<comments>http://transfixedbutnotdead.com/2010/01/04/receiving-contributions-to-your-github-project/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 20:52:16 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=799</guid>
		<description><![CDATA[Received my first ever contribution to one of my Github projects today. A pull request from a cpanservice? And I wasn&#8217;t the only one or was wondering who this cpanservice is or was?
I suspect that this as something to do with the recent gitPAN upload to Github and therefore is probably some automated service that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=799&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Received my first ever contribution to one of my <a href="http://github.com/draegtun/builder">Github projects</a> today. A pull request from a <a href="http://github.com/cpanservice">cpanservice?</a> And I wasn&#8217;t the <a href="http://twitter.com/miyagawa/status/7317230829">only one</a> or was wondering who this <em>cpanservice</em> is or was?</p>
<p>I suspect that this as something to do with the recent <a href="http://github.com/gitpan/">gitPAN</a> upload to <a href="http://github.com">Github</a> and therefore is probably some automated service that is going through related projects making sure that Github CPAN projects do have the <a href="http://github.com/draegtun/builder/commit/df5a0cbdebcde2ec26bd41b2fa190d3dd66d929e">meta repository tag populated</a> in the build process.  </p>
<p><em>NB. I blogged about this repository link back in <a href="http://transfixedbutnotdead.com/2009/05/01/repository-link-now-appearing-on-cpan/">May</a> but forgot to put my changes live.</em> *blush*</p>
<p>This contribution was the necessary nudge I needed to find out how to use git to merge in external changes.  Github itself did seem to provide a web option to apply this change directly under &#8220;Fork Queue&#8221;.  However I wanted to do it all via git so first place I looked is the Github documention on <a href="http://github.com/guides/pull-requests">pull requests</a>.</p>
<p>My local directory was up-to-date so I just needed to do the following to pull &amp; merge into my code:</p>
<ul>
<li><code>git pull git://github.com/cpanservice/builder.git master</code></li>
</ul>
<p>All merged and committed (see PS).  Quick check of diffs &amp; logs and then just needed to populate it back to Github:</p>
<ul>
<li><code>git push origin master</code></li>
</ul>
<p>You will see <em>cpanservice</em> changes immediately in the commits.   However the Github graphs and fork queue take a little while to be updated to show the merge.</p>
<p>/I3az/</p>
<p>&nbsp;</p>
<p>PS. The merged <em>cpanservice</em> changes showed up under me in the network graph (see red line below) despite showing up correctly under commits.  </p>
<p><a href="http://www.flickr.com/photos/draegtun/4245104639/" title="github-builder-graph by draegtun, on Flickr"><img src="http://farm5.static.flickr.com/4061/4245104639_f111617a60.jpg" width="500" height="128" alt="github-builder-graph" /></a></p>
<p>I think this is because I merge changes locally and then pushed back to Github?  Its not an issue for these <em>cpanservice</em> changes but I would like to get it right for &#8220;proper&#8221; contributors.   </p>
<p>So I think the alternate merge example documented by Github might be the better approach?</p>
<p><code>git remote add defunkt git://github.com/defunkt/grit.git<br />
 git fetch defunkt<br />
 git merge defunkt/master</code></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/799/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/799/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/799/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/799/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/799/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/799/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/799/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/799/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/799/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/799/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=799&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2010/01/04/receiving-contributions-to-your-github-project/feed/</wfw:commentRss>
		<slash:comments>2</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>

		<media:content url="http://farm5.static.flickr.com/4061/4245104639_f111617a60.jpg" medium="image">
			<media:title type="html">github-builder-graph</media:title>
		</media:content>
	</item>
		<item>
		<title>Couple of CPAN pressies</title>
		<link>http://transfixedbutnotdead.com/2009/12/26/couple-of-cpan-pressies/</link>
		<comments>http://transfixedbutnotdead.com/2009/12/26/couple-of-cpan-pressies/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 23:17:02 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[CPAN]]></category>
		<category><![CDATA[Devel::Declare]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=783</guid>
		<description><![CDATA[Just uploaded a couple of new modules to CPAN:

Acme::URL
PerlX::QuoteOperator

The first one you is just a small xmas cracker that you will already know about from my &#8220;bare URL&#8221; post from last week.  Just pull, enjoy for a little while and then chuck away like most xmas cracker toys  
The second one is a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=783&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Just uploaded a couple of new modules to CPAN:</p>
<ul>
<li><a href="http://search.cpan.org/dist/Acme-URL/">Acme::URL</a>
<li><a href="http://search.cpan.org/dist/PerlX-QuoteOperator/">PerlX::QuoteOperator</a>
</ul>
<p>The first one you is just a small xmas cracker that you will already know about from my <a href="http://transfixedbutnotdead.com/2009/12/16/url-develdeclare-and-no-strings-attached/">&#8220;bare URL&#8221;</a> post from last week.  Just pull, enjoy for a little while and then chuck away like most xmas cracker toys <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The second one is a tad similar (ie. <a href="http://search.cpan.org/dist/Devel-Declare/">Devel::Declare</a>) but with a much more sympathetic syntax by allowing you to create new <a href="http://perldoc.perl.org/perlop.html#Quote-Like-Operators">Quote-Like Operators</a> in Perl with Perl.   </p>
<p>For a good end product exemplar have a look at <a href="http://search.cpan.org/dist/PerlX-QuoteOperator/lib/PerlX/QuoteOperator/URL.pm">PerlX::QuoteOperator::URL</a> included with the distribution:</p>
<pre class="brush: perl;">
use PerlX::QuoteOperator::URL 'qh';

my $content = qh{ http://transfixedbutnotdead.com/ };
</pre>
<p>There is no scary parsing going on with this example.  PerlX::QuoteOperator / Devel::Declare simply hits the &#8216;qh&#8217; keyword and converts it to:</p>
<pre class="brush: perl;">
qh qq{ http://transfixedbutnotdead.com/ }
</pre>
<p>And &#8216;qh&#8217; is a subroutine with a ($) prototype.   So nothing too sinister (unless you really do abhor subroutine prototypes!), just a simple macro which gives the appearance that we have new quote-like operators.</p>
<p>Certainly an interesting concept to be able to produce new quote-like operators in Perl.  So hopefully PerlX::QuoteOperator might find its way under a few xmas trees <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Merry Xmas &amp; happy St. Stephen&#8217;s day to everyone.</p>
<p>/I3az/</p>
<p>PS.  I chose the PerlX::* because <a href="http://search.cpan.org/~gugod/">gugod</a> as already provided some wonderful Devel::Declare Perl extending modules under this <a href="http://search.cpan.org/search?query=perlx%3A%3A*&amp;mode=distributions">namespace</a>.   I feel its in the same vein so hopefully a good place for it to live.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/783/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/783/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/783/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=783&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2009/12/26/couple-of-cpan-pressies/feed/</wfw:commentRss>
		<slash:comments>2</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>Contributing to a project on Github</title>
		<link>http://transfixedbutnotdead.com/2009/12/24/contributing-to-a-project-on-github/</link>
		<comments>http://transfixedbutnotdead.com/2009/12/24/contributing-to-a-project-on-github/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 21:20:43 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Devel::Declare]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=771</guid>
		<description><![CDATA[After getting my head into Devel::Declare::Context::Simple to create the bare URL for my last blog post
I realised that I&#8217;ve percolated enough knowledge about the module that it would be a good idea to redirect it back to the project by at least doing the POD.
This will be the first time I&#8217;ve &#8220;properly&#8221; contributed in some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=771&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>After getting my head into Devel::Declare::Context::Simple to create the bare URL for my <a href="http://transfixedbutnotdead.com/2009/12/16/url-develdeclare-and-no-strings-attached/">last blog post</a><br />
I realised that I&#8217;ve percolated enough knowledge about the module that it would be a good idea to redirect it back to the project by at least doing the POD.</p>
<p>This will be the first time I&#8217;ve &#8220;properly&#8221; contributed in some form to an opensource project (&#8220;properly&#8221; being via source control management &amp; a patch).</p>
<p><a href="http://search.cpan.org/dist/Devel-Declare/">Devel::Declare</a> is hosted on <a href="http://github.com/rafl/devel-declare">Github here</a>.   And the process to contribute back changes to a Github project is &#8220;forking&#8221; simple!</p>
<p>With <a href="http://git-scm.com/">Git</a> &amp; <a href="http://github.com">Github</a> its all about forking.  Here is a concise Github <a href="http://help.github.com/forking/">howto</a> (which I&#8217;ll regurgitate below with my own slant &amp; spiel!).</p>
<p>I only use Git for my Github projects, so forking etc is all new to me.  To break it down into a few simple steps the process to contribute would be:</p>
<ul>
<li>Fork project
<li>Clone your fork
<li>Make your changes
<li>Push changes back to you fork
<li>Send pull request back to original project
</ul>
<p>&nbsp;</p>
<p>Here are the minutiae steps I went through for Devel::Declare:</p>
<ul>
<li>Went to <a href="http://github.com/rafl/devel-declare">Devel::Declare project</a> on Github and forked it.
<li>Forked project now appears in my project list.
<li>Cloned my forked Devel::Declare (use &#8220;Your Clone URL&#8221; copy/paste)<br />
<code>git clone git@github.com:draegtun/devel-declare.git<br />
cd devel-declare/<br />
</code></p>
<li>Linked my forked project to original<br />
<code>git remote add upstream git://github.com/rafl/devel-declare.git<br />
git fetch upstream<br />
</code></p>
<li>Make my changes to project
<li>Run tests (in case I did something stupid!)<br />
<code>perl Makefile.PL<br />
make<br />
make test<br />
</code></p>
<li>Clear down build once happy<br />
<code>make realclean</code></p>
<li>Push my changes back to my fork<br />
<code>git commit -a -m "Documentation added to D::D::Context::Simple + examples directory"<br />
git push origin master<br />
</code>
</ul>
<p>Now on Github the changes can be seen in <a href="http://github.com/draegtun/devel-declare">my fork</a></p>
<p>All I do now is click the &#8220;pull request&#8221; button and off went a request of my changes to <a href="http://github.com/rafl">rafl</a>.  Fingers cross my documentation changes were good enough to be accepted.</p>
<p>So I&#8217;m no longer a virgin to contributing to this opensource malarky <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>/I3az/</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/771/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/771/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/771/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/771/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/771/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=771&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2009/12/24/contributing-to-a-project-on-github/feed/</wfw:commentRss>
		<slash:comments>4</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>URL, Devel::Declare and no strings attached</title>
		<link>http://transfixedbutnotdead.com/2009/12/16/url-develdeclare-and-no-strings-attached/</link>
		<comments>http://transfixedbutnotdead.com/2009/12/16/url-develdeclare-and-no-strings-attached/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 16:55:24 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Devel::Declare]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=753</guid>
		<description><![CDATA[This Hacker News article caught my eye yesterday which pointed to a blog post about having a raw URL within a Ruby program using some clever shenanigans. (They you go, I saved you having to click through to find all the links yourself!)
Some examples from blog post:

# display this JSON request
puts http://github.com/defunkt.json

# =&#62; &#34;He nose [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=753&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>This <a href="http://news.ycombinator.com/item?id=994716">Hacker News article</a> caught my eye yesterday which pointed to a <a href="http://ozmm.org/posts/urls_in_ruby.html">blog post</a> about having a raw <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator">URL</a> within a Ruby program using some <a href="http://gist.github.com/255948">clever shenanigans</a>. <em>(They you go, I saved you having to click through to find all the links yourself!)</em></p>
<p>Some examples from blog post:</p>
<pre class="brush: ruby;">
# display this JSON request
puts http://github.com/defunkt.json

# =&gt; &quot;He nose the truth.&quot;
require 'json'
url = http://twitter.com/statuses/show/6592721580.json
JSON.parse(url.to_s)['text']
</pre>
<p>Very clever indeed.  Of course there will be some edge cases but it does show you how far you can stretch Ruby.  <em>NB. Didn&#8217;t work in 1.9 for me but worked with minor warning in 1.8.2 (yes I know it old but thats what shipped with Mac OSX Tiger).</em></p>
<p>So how far can we stretch Perl?  Well with <a href="http://search.cpan.org/dist/Devel-Declare/">Devel::Declare</a> it can be stretched all the way:</p>
<pre class="brush: perl;">
use Modern::Perl;
use JSON qw(decode_json);
use URLDSL;

# print the json
say http://twitter.com/statuses/show/6592721580.json;

# =&gt; &quot;He nose the truth.&quot;
say decode_json( http://twitter.com/statuses/show/6592721580.json )-&gt;{text};
</pre>
<p>So Perl also has no strings attached <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Devel::Declare allow us to extend the Perl syntax in a robust and easy fashion:</p>
<pre class="brush: perl;">
package URLDSL;
use Modern::Perl;
use Devel::Declare ();
use LWP::Simple ();
use base 'Devel::Declare::Context::Simple';

sub import {
    my $class  = shift;
    my $caller = caller;
    my $ctx    = __PACKAGE__-&gt;new;

    Devel::Declare-&gt;setup_for(
        $caller,
        {
            http =&gt; {
                const =&gt; sub { $ctx-&gt;parser(@_) },
            },
        },
    );

    no strict 'refs';
    *{$caller.'::http'} = sub ($) { LWP::Simple::get( $_[0] ) };
}

sub parser {
    my $self = shift;
    $self-&gt;init(@_);
    $self-&gt;skip_declarator;          # skip past &quot;http&quot;

    my $line = $self-&gt;get_linestr;   # get me current line of code
    my $pos  = $self-&gt;offset;        # position just after &quot;http&quot;
    my $url  = substr $line, $pos;   # url &amp; everything after &quot;http&quot;

    for my $c (split //, $url) {
        # if blank, semicolon or closing parenthesis then no longer a URL
        last if $c eq q{ };
        last if $c eq q{;};
        last if $c eq q{)};
        $pos++;
    }    

    # wrap the url with http() sub and quotes
    substr( $line, $pos,          0 ) = q{&quot;)};
    substr( $line, $self-&gt;offset, 0 ) = q{(&quot;http};

    # pass back changes to parser
    $self-&gt;set_linestr( $line );

    return;
}

1;
</pre>
<p>&nbsp;</p>
<p>Here is a low level synopsis of how it worked:</p>
<ul>
<li>Devel::Declare tells the perl parser to call parser() when it hits <code>http</code> keyword</li>
<li><code>http://twitter.com/statuses/show/6592721580.json</code> example triggers this (perl has no problem naturally distinguishing &#8220;http&#8221; keyword from &#8220;http://&#8221;)</li>
<li>Get line of code in question (<code>my $line = $self-&gt;get_linestr; </code>)
<li>parser() skips along the URL data following &#8220;http&#8221; (<code>$self-&gt;offset</code>) until it reaches a space, semicolon or a closing bracket (this covers &#8220;most&#8221; cases though comma could be an issue).  This marks the end of the URL data</li>
<li>We now in essence change <code>http://twitter.com/statuses/show/6592721580.json</code> into <code>http("http://twitter.com/statuses/show/6592721580.json")</code></li>
<li>And plonk the changed line back to the parser (<code>$self-&gt;set_linestr($line);</code>) and let it continue along its merry way</li>
<li>NB. http() sub was already imported into calling space and returns a <a href="http://search.cpan.org/dist/libwww-perl/lib/LWP/Simple.pm">LWP::Simple::get</a> of the requested URL</li>
</ul>
<p>&nbsp;</p>
<p>Now is URLDSL useful in the real world?   It can screw up syntax highlighting a bit (though WordPress highlighter coped extremely well, unlike <a href="http://gist.github.com/256992">Github</a> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Its robust enough to cope with normal string interpolation:</p>
<pre class="brush: perl;">
my $id = '6592721580';
say decode_json( http://twitter.com/statuses/show/$id.json )-&gt;{text};
</pre>
<p>So perhaps I should upload it to CPAN? (earmarked for ACME:: perhaps!?).  Anyone think this is useful little helper module then I wrap it up the next time I get a free moment.</p>
<p>The exercise as been fruitful in allowing me to get my head into the amazing Devel::Declare module for the first time. </p>
<p>I&#8217;ve used the Devel::Declare::Context::Simple class which simplifies things.  Unfortunately there isn&#8217;t a POD on this yet but the main Devel::Declare docs nicely demonstrate the correct mechanics so its easy to adapt from this.</p>
<p>I also found this <a href="http://lumberjaph.net/blog/index.php/2009/11/09/modules-i-like-develdeclare/">blog post by franck cuny</a> to be extremely helpful.  As was delving through the source code of <a href="http://cpants.perl.org/dist/used_by/Devel-Declare">other modules that used Devel::Declare</a></p>
<p>/I3az/</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/753/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=753&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2009/12/16/url-develdeclare-and-no-strings-attached/feed/</wfw:commentRss>
		<slash:comments>6</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>Keeping to a schedule</title>
		<link>http://transfixedbutnotdead.com/2009/12/13/keeping-to-a-schedule/</link>
		<comments>http://transfixedbutnotdead.com/2009/12/13/keeping-to-a-schedule/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 14:28:05 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=747</guid>
		<description><![CDATA[When I made my Blogging Milestone post I decided to have a crack of writing Perl posts to a fixed schedule.
The Blogging Milestone post marked ten days since the previous post (ie. the Iron Man limit!).  The following posts would continue to happen but reduced by a day each time.  So next was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=747&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>When I made my <a href="http://transfixedbutnotdead.com/2009/10/22/blogging-milestone/">Blogging Milestone</a> post I decided to have a crack of writing Perl posts to a fixed schedule.</p>
<p>The <i>Blogging Milestone</i> post marked ten days since the previous post (ie. the Iron Man limit!).  The following posts would continue to happen but reduced by a day each time.  So next was 9 days later&#8230; then 8 days later&#8230; then 7 days later&#8230; until I reached zero days&#8230;  <a href="http://transfixedbutnotdead.com/2009/12/06/to-do-or-not-to-do-that-is-the-question/">my last post</a>.</p>
<p>Phew&#8230; it did take a bit of effort to keep to a strict deadline but it is a good carrot &amp; stick to keep you going!    </p>
<p>Obviously I felt confident enough that I could do it (but not confident enough to announce that I was doing it!) and having lots of blog ideas written down + some partially composed ones does help <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>For all those posters that are doing Perl advent calendars at the moment I know what you must be going through and my hats off to you all.</p>
<p>/I3az/</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/747/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/747/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/747/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=747&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2009/12/13/keeping-to-a-schedule/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>to DO or not to DO, that is the question</title>
		<link>http://transfixedbutnotdead.com/2009/12/06/to-do-or-not-to-do-that-is-the-question/</link>
		<comments>http://transfixedbutnotdead.com/2009/12/06/to-do-or-not-to-do-that-is-the-question/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 10:12:52 +0000</pubDate>
		<dc:creator>draegtun</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://transfixedbutnotdead.com/?p=741</guid>
		<description><![CDATA[Following on from yesterdays post about do blocks, this is what I would normally do off the bat:

sub word_freq {
    my %words;
    $words{$_}++ for split /\s+/, lc $_[0];
    \%words;
}

Returning back a hash reference is both leaner and meaner  

use List::Util qw(sum);

my $s = &#34;The green [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=741&subd=draegtun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Following on from <a href="http://transfixedbutnotdead.com/2009/12/05/anything-you-can-do-i-can-do-better/">yesterdays post about do blocks</a>, this is what I would normally do off the bat:</p>
<pre class="brush: perl;">
sub word_freq {
    my %words;
    $words{$_}++ for split /\s+/, lc $_[0];
    \%words;
}
</pre>
<p>Returning back a hash reference is both leaner and meaner <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<pre class="brush: perl;">
use List::Util qw(sum);

my $s = &quot;The green hat is tHe twin of the green hat&quot;;

my $num_of_hats = word_freq( $s )-&gt;{ hat };   # word count just for 'hat'

# don't worry... always unique hashrefs returned:
my $hash_ref    = word_freq( $s );
my $hash_ref2   = word_freq( $s );       

# thus you can safely:
$hash_ref2-&gt;{green} = 100;
say &quot;$hash_ref-&gt;{green} : $hash_ref2-&gt;{green}&quot;; # =&gt; &quot;2 : 100&quot;    

# clean copy for those who prefer there hashes not to be hashrefs!
my %hash = %{ word_freq( $s ) };       

# returns ( 'is', 'of')
my @two_letter_words  = grep { length $_ == 2 } keys %{ word_freq( $s ) };

# number of &quot;green&quot; + &quot;hat&quot; == 4
my $green_plus_hat = sum @{ word_freq( $s ) }{ qw/green hat/ };
</pre>
<p>&nbsp;</p>
<p>And what I probably wouldn&#8217;t do is:</p>
<pre class="brush: perl;">
use List::MoreUtils qw(uniq);

my $s = &quot;The green hat is tHe twin of the green hat&quot;;

my %words = do {
    my @words = split /\s+/, lc $s;
    map {
        my $word = $_;
        $word =&gt; scalar grep { $_ eq $word } @words;
    } uniq @words
};
</pre>
<p>I actually prefer the code aesthetics of this but the extra cycle (grep) through @words pushes me towards the leaner hash counting solution.   Horses for courses?  <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>/I3az/</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/draegtun.wordpress.com/741/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/draegtun.wordpress.com/741/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/draegtun.wordpress.com/741/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/draegtun.wordpress.com/741/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/draegtun.wordpress.com/741/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/draegtun.wordpress.com/741/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/draegtun.wordpress.com/741/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/draegtun.wordpress.com/741/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/draegtun.wordpress.com/741/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/draegtun.wordpress.com/741/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=transfixedbutnotdead.com&blog=351142&post=741&subd=draegtun&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://transfixedbutnotdead.com/2009/12/06/to-do-or-not-to-do-that-is-the-question/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>
	</channel>
</rss>