<?xml version="1.0"?>
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
  <channel>
    <title>Random notes   </title>
    <link>/blog</link>
    <description>A pile of assorted scribblings, snippets and ramblings (mostly about programming and the software that makes my life easier).</description>
    <language>en</language>

  <item>
    <title>Devel::Declare, Method::Signatures, oh my</title>
    <link>/blog/2010/11/29#devel-declare</link>
    <description>&lt;p&gt;Actually, I got another inspiration from Method::Signatures, for use with
CGI::Application.&lt;/p&gt;

&lt;p&gt;But while implementing that, I decided to extract the hard Devel::Declare
bits, and make a macro installer.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s a re-implementation of Method::Signatures using my Devel::Declare::Macro:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; package Method::Signatures;
 use Devel::Declare::Macro;

 sub import {
  install_macro(
    into           =&amp;gt; scalar(caller),
    name           =&amp;gt; 'method',
    proto_parser   =&amp;gt; \&amp;amp;make_proto_unwrap,
    proto_injector =&amp;gt; \&amp;amp;inject_from_signature
  );
 }

 sub make_proto_unwrap {} # as before, except return \%signature
 sub inject_from_signature {} # as before
 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I&amp;#8217;m somewhat confident it could simplify the implementation of Sub::Curried
and MooseX::Method::Signatures as well.&lt;/p&gt;

&lt;p&gt;Basically it packages the synopsis of Devel::Declare. As such, I don&amp;#8217;t think I
should maintain it. Comments welcome.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  package Devel::Macro;

  sub import {
      my &amp;#036;class = shift;
      my &amp;#036;pkg = caller;
      no strict 'refs';
      *{&amp;#036;pkg.'::install_macro'} = \&amp;amp;install_macro;
  }

  # Stolen from Devel::Declare's t/method-no-semi.t
  use Devel::Declare ();
  use Scope::Guard;
  use Sub::Name;
  sub install_macro {
      my %args   = @_;
      # I don't really understand why we need to declare method
      # in the caller's namespace.
      {
          no strict 'refs';
          *{&amp;#036;args{into}.'::'.&amp;#036;args{name}}   = sub (&amp;amp;) {};
      }
      Devel::Declare-&amp;gt;setup_for(
          &amp;#036;args{into},
          { &amp;#036;args{name} =&amp;gt; {
              const =&amp;gt; mk_parser(
                  &amp;#036;args{proto_parser}||sub{''},
                  &amp;#036;args{proto_injector}||sub{join' ', @_},
                  &amp;#036;args{pre_install}||sub{},
                  )
              },
          },
      );

  }
  our (&amp;#036;Declarator, &amp;#036;Offset);

  sub skip_declarator {
      &amp;#036;Offset += Devel::Declare::toke_move_past_token(&amp;#036;Offset);
  }

  sub skipspace {
      &amp;#036;Offset += Devel::Declare::toke_skipspace(&amp;#036;Offset);
  }

  sub strip_name {
      skipspace;
      if (my &amp;#036;len = Devel::Declare::toke_scan_word(&amp;#036;Offset, 1)) {
          my &amp;#036;linestr = Devel::Declare::get_linestr();
          my &amp;#036;name = substr(&amp;#036;linestr, &amp;#036;Offset, &amp;#036;len);
          substr(&amp;#036;linestr, &amp;#036;Offset, &amp;#036;len) = '';
          Devel::Declare::set_linestr(&amp;#036;linestr);
          return &amp;#036;name;
      }
      return;
  }

  sub strip_proto {
      skipspace;

      my &amp;#036;linestr = Devel::Declare::get_linestr();
      if (substr(&amp;#036;linestr, &amp;#036;Offset, 1) eq '(') {
          my &amp;#036;length = Devel::Declare::toke_scan_str(&amp;#036;Offset);
          my &amp;#036;proto = Devel::Declare::get_lex_stuff();
          Devel::Declare::clear_lex_stuff();
          &amp;#036;linestr = Devel::Declare::get_linestr();
          substr(&amp;#036;linestr, &amp;#036;Offset, &amp;#036;length) = '';
          Devel::Declare::set_linestr(&amp;#036;linestr);
          return &amp;#036;proto;
      }
      return;
  }

  sub shadow {
      my &amp;#036;pack = Devel::Declare::get_curstash_name;
      Devel::Declare::shadow_sub(&quot;&amp;#036;{pack}::&amp;#036;{Declarator}&quot;, &amp;#036;_[0]);
  }

  sub inject_if_block {
      my &amp;#036;inject = shift;
      skipspace;
      my &amp;#036;linestr = Devel::Declare::get_linestr;
      if (substr(&amp;#036;linestr, &amp;#036;Offset, 1) eq '{') {
          substr(&amp;#036;linestr, &amp;#036;Offset+1, 0) = &amp;#036;inject;
          Devel::Declare::set_linestr(&amp;#036;linestr);
      }
  }

  sub scope_injector_call {
      return ' BEGIN { ' . __PACKAGE__ . '::inject_scope }; ';
  }

  sub mk_parser {
      my &amp;#036;proto_parser   = shift;
      my &amp;#036;proto_injector = shift;
      my &amp;#036;install_cb     = shift;

      return sub {
      local (&amp;#036;Declarator, &amp;#036;Offset) = @_;
      skip_declarator;
      my &amp;#036;name = strip_name;
      my &amp;#036;proto = strip_proto;
      my @decl = &amp;#036;proto_parser-&amp;gt;(&amp;#036;proto);
      my &amp;#036;inject = &amp;#036;proto_injector-&amp;gt;(@decl);
      if (defined &amp;#036;name) {
          &amp;#036;inject = scope_injector_call().&amp;#036;inject;
      }
      inject_if_block(&amp;#036;inject);
      if (defined &amp;#036;name) {
          &amp;#036;name = join('::', Devel::Declare::get_curstash_name(), &amp;#036;name)
            unless (&amp;#036;name =~ /::/);
      }
      shadow(sub (&amp;amp;) {
          no strict 'refs';
          my &amp;#036;code = shift;
          &amp;#036;install_cb-&amp;gt;(&amp;#036;name, &amp;#036;code, \@decl);
          # So caller() gets the subroutine name
          *{&amp;#036;name} = subname &amp;#036;name =&amp;gt; &amp;#036;code if defined &amp;#036;name;
      });
      };
  }

  sub inject_scope {
      &amp;#036;^H |= 0x120000;
      &amp;#036;^H{DD_METHODHANDLERS} = Scope::Guard-&amp;gt;new(sub {
          my &amp;#036;linestr = Devel::Declare::get_linestr;
          my &amp;#036;offset = Devel::Declare::get_linestr_offset;
          substr(&amp;#036;linestr, &amp;#036;offset, 0) = ';';
          Devel::Declare::set_linestr(&amp;#036;linestr);
      });
  }

  1;
&lt;/code&gt;&lt;/pre&gt;
</description>
  </item>

  <item>
    <title>Some of my favorite applications</title>
    <link>/blog/2010/11/29#list</link>
    <description>&lt;p&gt;In no particular order, the following applications make my life so much easier:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;debian/ubuntu&lt;/li&gt;
&lt;li&gt;gaim&lt;/li&gt;
&lt;li&gt;galeon&lt;/li&gt;
&lt;li&gt;gnome&lt;/li&gt;
&lt;li&gt;liferea&lt;/li&gt;
&lt;li&gt;pan&lt;/li&gt;
&lt;li&gt;perl&lt;/li&gt;
&lt;li&gt;privoxy&lt;/li&gt;
&lt;li&gt;rhythmbox&lt;/li&gt;
&lt;li&gt;subversion&lt;/li&gt;
&lt;li&gt;thunderbird&lt;/li&gt;
&lt;li&gt;vim&lt;/li&gt;
&lt;/ul&gt;
</description>
  </item>

  <item>
    <title>Email::MIME::* modules aren&amp;#8217;t very close friends</title>
    <link>/blog/2010/11/29#attachment_stripper</link>
    <description>&lt;p&gt;The &lt;a href=&quot;http://emailproject.perl.org/&quot; title=&quot;The Perl Email Project&quot;&gt;&lt;code&gt;Email::*&lt;/code&gt;&lt;/a&gt; modules are all pretty neat, with a pleasant API. But 
combining them isn&amp;#8217;t always as effortless as you&amp;#8217;d expect.&lt;/p&gt;

&lt;p&gt;For my email2blog script, I use &lt;a href=&quot;http://search.cpan.org/dist/Email-Filter&quot;&gt;&lt;code&gt;Email::Filter&lt;/code&gt;&lt;/a&gt; as the bridge between the 
MTA and blosxom:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; # grab email from STDIN
 my &amp;#036;mail = Email::Filter-&amp;gt;new;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;&amp;#036;mail&lt;/code&gt; object has nifty methods that make it very simple to accept or 
reject a message.&lt;/p&gt;

&lt;p&gt;Once I accept a message, I take out the attachments with 
&lt;a href=&quot;http://search.cpan.org/dist/Email-MIME-Attachment-Stripper&quot;&gt;&lt;code&gt;Email::MIME::Attachment::Stripper&lt;/code&gt;&lt;/a&gt;. The first step is to construct a 
stripper based on the incoming email:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; # make stripper
 my &amp;#036;strip = Email::MIME::Attachment::Stripper-&amp;gt;new(
             Email::MIME-&amp;gt;new( &amp;#036;mail-&amp;gt;simple-&amp;gt;as_string ),
             force_filename =&amp;gt; 1
 );
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I&amp;#8217;m not impressed with the hoops I have to jump through there. It should be 
easy for &lt;code&gt;EMA::Stripper&lt;/code&gt; to build its own &lt;a href=&quot;http://search.cpan.org/dist/Email-MIME&quot;&gt;&lt;code&gt;Email::MIME&lt;/code&gt;&lt;/a&gt; object when 
handed an &lt;code&gt;Email::Simple&lt;/code&gt; object. But in fact, even &lt;code&gt;Email::MIME&lt;/code&gt; itself 
doesn&amp;#8217;t offer that option.&lt;/p&gt;

&lt;p&gt;Next up is taking apart the MIME email:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; # strip attachments
 my &amp;#036;msg = &amp;#036;strip-&amp;gt;message;
 my @attachments = &amp;#036;strip-&amp;gt;attachments;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#8217;s pretty straightforward. &lt;code&gt;&amp;#036;msg&lt;/code&gt; is an &lt;code&gt;Email::MIME&lt;/code&gt; object, without the 
attachments. To get at the plaintext body is still not very comfortable:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; # extract plaintext body
 my &amp;#036;text = first { &amp;#036;_-&amp;gt;content_type =~ m{text/plain} } &amp;#036;msg-&amp;gt;parts;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Maybe that&amp;#8217;s because there may not be a &lt;code&gt;text/plain&lt;/code&gt; part with meaningful 
content, but I wouldn&amp;#8217;t expect &lt;code&gt;&amp;#036;msg-&amp;gt;body&lt;/code&gt; to be empty after the strip 
operation. It is though, so that fancy grep is necessary.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;@attachments&lt;/code&gt; array on the other hand is very easy to work with. It has 
just the things you need, and nothing else.&lt;/p&gt;

&lt;p&gt;All in all, the script ended up being about 60 well-spaced lines long, with 
most of that being taken up by sanitizing the input. The fact that I didn&amp;#8217;t 
actually have to think how MIME encoding works under the hood was a big plus, 
and for that I&amp;#8217;m very happy with the &lt;a href=&quot;http://emailproject.perl.org/&quot; title=&quot;The Perl Email Project&quot;&gt;PEP Project&lt;/a&gt;.&lt;/p&gt;
</description>
  </item>

  <item>
    <title>First impressions</title>
    <link>/blog/2010/11/29#install</link>
    <description>&lt;p&gt;I installed &lt;a href=&quot;http://www.blosxom.com/&quot; title=&quot;Blosxom&quot;&gt;Blosxom&lt;/a&gt; today. Getting it up and running was a piece of cake. Finding useful plugins took a little longer, but I&amp;#8217;m happy with the current set:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;categories, meta, directorybrowse, flavourdir&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://daringfireball.net/projects/markdown/&quot; title=&quot;Markdown&quot;&gt;MarkDown&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://daringfireball.net/projects/smartypants/&quot; title=&quot;SmartyPants&quot;&gt;SmartyPants&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I stole the layout from my &lt;a href=&quot;/perl&quot; title=&quot;Perl pages&quot;&gt;Perl pages&lt;/a&gt;.&lt;/p&gt;
</description>
  </item>

  <item>
    <title>Test Driven Development and refactoring</title>
    <link>/blog/2010/11/29#required_reading</link>
    <description>&lt;p&gt;On &lt;a href=&quot;http://safari.oreilly.com/&quot;&gt;Safari Bookshelf&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;#8220;Test-Driven Development By Example&amp;#8221;, Kent Beck&lt;/li&gt;
&lt;li&gt;&amp;#8220;Perl Testing: A Developer&amp;#8217;s Notebook&amp;#8221;, chromatic , Ian Langworth&lt;/li&gt;
&lt;li&gt;&amp;#8220;Refactoring: Improving the Design of Existing Code&amp;#8221;,
Martin Fowler, Kent Beck et al&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On &lt;a href=&quot;http://www.perlmonks.org/&quot;&gt;PerlMonks&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.perlmonks.org/?node_id=412451&quot;&gt;OT: TDD question&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.perlmonks.org/?node_id=292124&quot;&gt;TDD: a test drive and a confession&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.perlmonks.org/?node_id=292705&quot;&gt;TDD in Perl&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.perlmonks.org/?node_id=487104&quot;&gt;TDD with Coverage Analysis. Wow.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.perlmonks.org/?node_id=70694&quot;&gt;Refactoring&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other books I&amp;#8217;ve heard good things about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&amp;#8220;Code Complete&amp;#8221;, Second Edition, Steve McConnell&lt;/li&gt;
&lt;li&gt;&amp;#8220;The Pragmatic Programmer: From Journeyman to Master&amp;#8221;,
Andrew Hunt, David Thomas&lt;/li&gt;
&lt;/ul&gt;
</description>
  </item>

  <item>
    <title>Tidyhtml 0.01</title>
    <link>/blog/2010/11/29#version_0.01</link>
    <description>&lt;h3&gt;Initial version&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;ve just written a tiny blosxom plugin that cleans up your html.
It uses the 1.07_01 dev version of 
&lt;a href=&quot;http://search.cpan.org/dist/HTML-Tidy&quot; title=&quot;By PETDANCE&quot;&gt;&lt;code&gt;HTML::Tidy&lt;/code&gt;&lt;/a&gt;,
which in turn uses
&lt;a href=&quot;http://tidy.sourceforge.net&quot; title=&quot;HTML Tidy Project Page&quot;&gt;&lt;code&gt;libtidy&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Since this is the first ever version, I&amp;#8217;m just going to paste it here.
I&amp;#8217;ll build a proper release later on.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Blosxom Plugin: tidyhtml
# Author(s): Rhesa Rozendaal  
# Version: 0.01
# URL: http://oss.rhesa.com/blog/text/blosxom/plugins/tidyhtml

package tidyhtml;
use strict;

# --- Configurable variables -----

my &amp;#036;tidy_config = {
    tidy_mark     =&amp;gt; 'no',
    wrap          =&amp;gt; '120',
    indent        =&amp;gt; 'auto',
    output_xhtml  =&amp;gt; 'yes',
    char_encoding =&amp;gt; 'utf8',
    doctype       =&amp;gt; 'strict',
    add_xml_decl  =&amp;gt; 'yes',
    alt_text      =&amp;gt; 'photo',
};

# --------------------------------

use HTML::Tidy;

sub last {
    # only operate on html content types.
    return unless &amp;#036;blosxom::header-&amp;gt;{-type} =~ /html/;

    &amp;#036;blosxom::output = HTML::Tidy-&amp;gt;new( &amp;#036;tidy_config )
                                 -&amp;gt;clean( &amp;#036;blosxom::output );
    return;
}

sub start { 1 }

1;
&lt;/code&gt;&lt;/pre&gt;
</description>
  </item>

  <item>
    <title>JavaScript-driven syntax highlighting</title>
    <link>/blog/2010/11/29#code_highlighting</link>
    <description>&lt;p&gt;Based on &lt;a href=&quot;http://www.perlmonks.org/?node_id=606083&quot;&gt;a PerlMonks idea&lt;/a&gt;, I&amp;#8217;ve added syntax highlighting on code blocks.
The &lt;a href=&quot;/js/prettify-jaap.js&quot;&gt;javascript is here&lt;/a&gt;, and the &lt;a href=&quot;/css/prettify-jaap.css&quot;&gt;css here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;See &lt;a href=&quot;/blog/text/blosxom/plugins/tidyhtml/version_0.01.html&quot;&gt;this post&lt;/a&gt; for an example (you need javascript enabled for this).&lt;/p&gt;
</description>
  </item>

  <item>
    <title>Markdown</title>
    <link>/blog/2010/11/29#markdown</link>
    <description>&lt;p&gt;&lt;a href=&quot;http://daringfireball.net/projects/markdown/&quot;&gt;Markdown&lt;/a&gt; is neat.&lt;/p&gt;
</description>
  </item>

  <item>
    <title>This time, with attachments</title>
    <link>/blog/2010/11/29#with_attachments</link>
    <description>&lt;p&gt;&lt;img src=&quot;/images/brudderhood2.gif&quot; alt=&quot;crocs for teh win&quot; title=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s hear a &amp;#8220;YAY!&amp;#8221; :-)&lt;/p&gt;
</description>
  </item>

  <item>
    <title>A couple of Vim links</title>
    <link>/blog/2010/11/29#vim-links</link>
    <description>&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://jmcpherson.org/editing.html&quot;&gt;Efficient Editing With vim - Jonathan McPherson&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.viemu.com/a-why-vi-vim.html&quot;&gt;Why, oh WHY, do those #?@! nutheads use vi?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.vim.org/tips/tip_search_results.php?keywords=&amp;amp;order_by=rating&amp;amp;direction=descending&amp;amp;search=search&quot;&gt;Search vim online tips by rating&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;Emacs is far too &lt;em&gt;small&lt;/em&gt; to be a proper kitchen sink &amp;#8212; &lt;a href=&quot;http://xach.livejournal.com/90933.html?thread=140853#t140853&quot;&gt;david feuer&lt;/a&gt;&lt;/p&gt;
</description>
  </item>

  </channel>
</rss>

