<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Alex Balhatchet</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/alex_balhatchet/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/alex_balhatchet/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/alex_balhatchet//92</id>
    <updated>2013-04-20T14:54:56Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Travis CI ♥ Perl</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/alex_balhatchet/2013/04/travis-ci-perl.html" />
    <id>tag:blogs.perl.org,2013:/users/alex_balhatchet//92.4592</id>

    <published>2013-04-20T14:25:14Z</published>
    <updated>2013-04-20T14:54:56Z</updated>

    <summary>Travis CI is a hosted continuous integration service for the open source community. Essentially you set up a git post-commit hook that causes your tests to get run on every commit, against a number of different Perl versions, with databases...</summary>
    <author>
        <name>Alex Balhatchet</name>
        <uri>http://kaoru.slackwise.net</uri>
    </author>
    
    <category term="continuousintegration" label="continuous integration" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="git" label="git" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="github" label="github" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="testing" label="testing" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="travisci" label="travis-ci" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/alex_balhatchet/">
        <![CDATA[<p>Travis CI is a hosted continuous integration service for the open source community.</p>

<p>Essentially you set up a git post-commit hook that causes your tests to get run on every commit, against a number of different Perl versions, with databases and other services available if needed. And it's all free!</p>

<p>If you visit <a href="https://travis-ci.org/">https://travis-ci.org/</a> you can get a feel for the interface and the tests that are being run. For a particular commit you get a build, for example <a href="https://travis-ci.org/kaoru/WebService-Nestoria-Search/builds/6470852"> WebService::Nestoria::Search build 1</a>, which has a sub-build per Perl version, for example <a href="https://travis-ci.org/kaoru/WebService-Nestoria-Search/jobs/6470853">WebService::Nestoria::Search build 1.1 (perl 5.16)</a>. As you can see you get the full output from the Ubuntu VM that's running your tests, so if anything does go wrong it's pretty simple to debug.</p>

<p>For the rest of this post I'm going to describe the integration process, in particular hitting on how to make it work with Dist::Zilla-based projects.</p>]]>
        <![CDATA[<p><big><strong>Travis CI Basics</strong></big></p>

<p>If you're using Github this couldn't be easier. Log into Travis CI with your Github account, go to your Travis CI profile, and flip your projects from Off to On. That causes a Github-side post-commit hook to be set up so that every time you 'git push' up to Github a Travis build will run.</p>

<p>Then you need to set up your .travis.yml file and commit it to your repository.  Here's an example from a "normal" (non-Dist::Zilla) distribution:</p>

<pre><code>
language: perl
perl:
  - "5.16"
  - "5.14"
  - "5.12"
  - "5.10"

<p></code></pre></p>

<p>That's it, that's the whole file! Travis knows from 'language: perl' that it should look for a Makefile.PL or Build.PL, install the dependencies, and then run the tests.</p>

<p>Once you commit that you should be able to head back to <a href="https://travis-ci.org/">Travis CI</a> and see the "My Repositories" tab and see that your tests are either running or have run.</p>

<p><big><strong>Travis CI + Dist::Zilla</strong></big></p>

<p>At the time of writing Travis CI does not support Perl distributions that don't have either a Makefile.PL or a Build.PL file. However there are a few different options for how to support a project that only has a dist.ini file...</p>

<p><strong>Add this functionality to Travis CI</strong></p>

<p>Travis is open source, you can see (and fork) it here: <a href="https://github.com/travis-ci">https://github.com/travis-ci</a></p>

<p>I tried adding Dist::Zilla support and failed, mostly due to my lack of Ruby :-) I suspect if somebody headed on IRC and talked to rjbs and miyagawa a solution could be found, since they both got involved on Github when I made my attempt and were very helpful in pointing out my errors and showing me towards the ways below.</p>

<p><strong>Tell Travis CI to do the "right" thing for your project only</strong></p>

<p>The .travis.yml file is incredibly flexible, up to and including allowing you to run arbitrary commands before and instead of the test process. That means if you make your .travis.yml file look like this...</p>

<pre><code>
language: perl
perl:
   - "5.16"
   - "5.14"
   - "5.12"
   - "5.10"

<p>before_install:<br />
   # Prevent "Please tell me who you are" errors for certain DZIL configs<br />
   - git config --global user.name "TravisCI"</p>

<p>install:<br />
   # Deal with all of the DZIL dependancies, quickly and quietly<br />
   - cpanm --quiet --notest --skip-satisfied Dist::Zilla<br />
   - dzil authordeps | grep -vP '[^\w:]' | xargs -n 5 -P 10 cpanm --quiet --notest --skip-satisfied</p>

<p>   - export RELEASE_TESTING=1 AUTOMATED_TESTING=1 AUTHOR_TESTING=1 HARNESS_OPTIONS=j10:c HARNESS_TIMER=1<br />
   - dzil listdeps | grep -vP '[^\w:]' | cpanm --verbose</p>

<p>script:<br />
   - dzil smoke --release --author</p>

<p></code></pre></p>

<p>... then your dist.ini-based module will be tested correctly, by causing it to run the appropriate cpanm and dzil commands to both install dependencies and run the tests themselves.</p>

<p>The Dist::Zilla plugin TravisYML (<a href="https://metacpan.org/release/Dist-Zilla-TravisCI">Dist::Zilla::TravisCI</a>) will generate the file above automatically as part of your 'dzil build' if you want to do it that way.</p>

<p>The downside is that installing Dist::Zilla every time is very slow so your tests will take a long time. Luckily there's another way...</p>

<p><strong>3. Use Git::CommitBuild and Travis CI branch whitelisting</strong></p>

<p>The Dist::Zilla plugin Git::CommitBuild (<a href="https://metacpan.org/module/Dist::Zilla::Plugin::Git::CommitBuild">Dist::Zilla::Plugin::Git::CommitBuild</a> causes your build to be committed on a separate branch each time you run 'dzil build', or a command which implies 'build' such as 'dzil test' or 'dzil release'.</p>

<p>Add the plugin to your dist.ini like so:</p>

<pre><code>
[Git::CommitBuild]
release_branch  = build/%b
release_message = Release build of v%v (on %b)

<p></code></pre></p>

<p>With that you get this:</p>

<pre><code>
alex@yuzu:~/Documents/Git/App-highlight$ git branch
  build/master
* master

<p>alex@yuzu:~/Documents/Git/App-highlight$ ls<br />
bin  Changes  dist.ini  lib  README.pod  t</p>

<p>alex@yuzu:~/Documents/Git/App-highlight$ git checkout build/master<br />
Switched to branch 'build/master'</p>

<p>alex@yuzu:~/Documents/Git/App-highlight$ ls<br />
bin  Changes  dist.ini  lib  LICENSE  Makefile.PL  MANIFEST  META.json  META.yml  README  README.pod  t</p>

<p></code></pre></p>

<p>As you can see the 'build/master' branch does have a Makefile.PL file, so Travis CI will be able to run its normal Perl testing against it. All that's left is to update your .travis.yml to tell Travis to run the tests on that branch only, like so:</p>

<pre><code>
language: perl
perl:
   - "5.16"
   - "5.14"
   - "5.12"
   - "5.10"

<p>branches:<br />
  only:<br />
    - /^build/</p>

<p></code></pre></p>

<p>You also need your .travis.yml file to exist on the build/master branch. To do that you need to update your dist.ini's GatherFiles and PruneCruft plugin options like so:</p>

<pre><code>
[GatherDir]
include_dotfiles = 1

<p>[PruneCruft]<br />
except = \.travis.yml</p>

<p></code></pre></p>

<p>And with your next commit (and push to github if that's where your Travis CI hook is set up) a Travis build should be kicked off!</p>

<p><strong>Useful Links</strong></p>

<p>Travis CI:</p>

<ul>
    <li><a href="https://travis-ci.org/">Travis CI Homepage</a></li>
    <li><a href="http://about.travis-ci.org/docs/">Travis CI Docs</a></li>
    <li><a href="https://github.com/">Github</a></li>
</ul>

<p>Examples:</p>

<ul>
    <li>HTTP::Async - normal CPAN distribution (not Dist::Zilla based)</li>
    <ul>
        <li><a href="https://github.com/evdb/HTTP-Async">Github</a></li>
        <li><a href="https://metacpan.org/release/HTTP-Async">MetaCPAN</a></li>
        <li><a href="https://travis-ci.org/evdb/HTTP-Async">Travis CI</a></li>
    </ul>
    <li>WebService::Nestoria::Search - Dist::Zilla based CPAN distribution</li>
    <ul>
        <li><a href="https://github.com/kaoru/WebService-Nestoria-Search">Github</a></li>
        <li><a href="https://metacpan.org/release/WebService-Nestoria-Search">MetaCPAN</a></li>
        <li><a href="https://travis-ci.org/kaoru/WebService-Nestoria-Search">Travis CI</a></li>
    </li>
</ul>

<p>Hope you found that useful. Happy testing :-)</p>]]>
    </content>
</entry>

<entry>
    <title>Better late than never - Perl School is awesome!</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/alex_balhatchet/2013/02/better-late-than-never---perl-school-is-awesome.html" />
    <id>tag:blogs.perl.org,2013:/users/alex_balhatchet//92.4380</id>

    <published>2013-02-25T06:38:52Z</published>
    <updated>2013-02-25T07:19:08Z</updated>

    <summary>Three Saturdays ago I attended the fourth Perl School, which was about DBIx::Class. Top line summary: it was brilliant! This was the second course I&apos;ve attended from Dave Cross, and the first one under the Perl School banner. Dave has...</summary>
    <author>
        <name>Alex Balhatchet</name>
        <uri>http://kaoru.slackwise.net</uri>
    </author>
    
    <category term="dbic" label="DBIC" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perlschool" label="perl school" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="training" label="training" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/alex_balhatchet/">
        <![CDATA[<p>Three Saturdays ago I attended the fourth <a href="http://perlschool.co.uk/">Perl School</a>, which was about <a href="https://metacpan.org/module/DBIx::Class">DBIx::Class</a>.</p>

<p>Top line summary: it was brilliant!</p>

<p>This was the second course I've attended from Dave Cross, and the first one under the <a href="http://perlschool.co.uk/">Perl School</a> banner. Dave has been using Perl heavily for around two decades up to and including this year, which gives him a very deep knowledge that is also firmly up-to-date. He is also an excellent presenter and trainer, so all that knowledge I just mentioned comes pouring out freely in a way that is easy to understand.</p>

<p>I would say that <a href="http://perlschool.co.uk/">Perl School</a>  is aimed at people more towards the "beginner" end of the spectrum, but the courses are focussed enough that as a Perl expert but a DBIC beginner I found it informative and interesting. I suspect that others would find the same holds for the "Object Oriented Programming with Perl and Moose" course that is also available. This is not a bad thing - I took this opportunity to bring along one of the less senior members of my team at Lokku, and I recommend others do the same. It also means that, unlike YAPC or LPW, the room was full of faces I didn't recognise. If those people can be converted into YAPC attendees then our community is going to grow and thrive.</p>

<p>I also know that Dave is looking to add more courses and to constantly improve <a href="http://perlschool.co.uk/">Perl School</a>, as is evident from the post-course survey and the conversations during the day itself. If you have any requests, comments, or ideas for courses please do contact him over on the <a href="http://perlschool.co.uk/feedback/">Feedback form on the site</a>.</p>

<p>If you're thinking to yourself that a course on Moose or DBIx::Class sounds great then you're in luck - Perl Schools 5 and 6 will be repeat performances of the Moose and DBIC courses, on April 6th and June 8th. At only £30 they are a bargain, there's really no excuse for not going!</p>

<p>I for one am really looking forward to seeing what happens with Perl School over the next year or so. I'm expecting great things :-)</p>]]>
        
    </content>
</entry>

<entry>
    <title>Ask JAPH - A Tumblr Experiment</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/alex_balhatchet/2013/02/ask-japh---a-tumblr-experiment.html" />
    <id>tag:blogs.perl.org,2013:/users/alex_balhatchet//92.4350</id>

    <published>2013-02-18T21:20:56Z</published>
    <updated>2013-02-18T21:28:07Z</updated>

    <summary>So Tumblr, well known blogging platform, has this feature where you can set up a simple site and then invite people to ask you questions. I thought it would be fun to try out doing this for Perl. http://askjaph.tumblr.com/ Why?...</summary>
    <author>
        <name>Alex Balhatchet</name>
        <uri>http://kaoru.slackwise.net</uri>
    </author>
    
    <category term="askjaph" label="askjaph" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="tumblr" label="tumblr" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/alex_balhatchet/">
        <![CDATA[<p>So Tumblr, well known blogging platform, has this feature where you can set up a simple site and then invite people to ask you questions. I thought it would be fun to try out doing this for Perl.</p>

<p><a href="http://askjaph.tumblr.com/">http://askjaph.tumblr.com/</a></p>

<p>Why?</p>

<ul>
	<li>Get the Perl name out there some more</li>
	<li>Offer yet another place other than Linked In and Stack Overflow for people to ask questions about Perl</li>
        <li>Teaching a subject is the best way to learn that subject</li>
        <li>Give me something to do with my abundance of free time (<i>this one is sarcastic...</i>)</li>
</ul>

<p>Not sure which to be more scared about - getting zero questions or getting lots of questions! But I'm more excited about getting lots of questions.</p>

<p>Whether you're completely new to Perl, or a Perl expert with a random question, you can always <a href="http://askjaph.tumblr.com/">Ask JAPH</a>!</p>

<p>Let's see how this goes :-)</p>]]>
        
    </content>
</entry>

<entry>
    <title>Experienced Perl Developer sought by Lokku Ltd (Nestoria)</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/alex_balhatchet/2012/08/experienced-perl-developer-sought-by-lokku-ltd-nestoria.html" />
    <id>tag:blogs.perl.org,2012:/users/alex_balhatchet//92.3667</id>

    <published>2012-08-08T10:42:31Z</published>
    <updated>2012-08-08T11:46:24Z</updated>

    <summary>(cross-posted from jobs@london.pm.org) ------------------------------------------------------------ Hi guys and girls, We&apos;re looking for a Perl developer with 2+ years of experience programming professionally to join our engineering team in central London, primarily to work on the Nestoria property search engine (http://www.nestoria.com) Nestoria...</summary>
    <author>
        <name>Alex Balhatchet</name>
        <uri>http://kaoru.slackwise.net</uri>
    </author>
    
    <category term="jobs" label="jobs" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="lokku" label="lokku" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="nestoria" label="nestoria" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/alex_balhatchet/">
        <![CDATA[<p>(cross-posted from jobs@london.pm.org)<br />
------------------------------------------------------------</p>

<p>Hi guys and girls,</p>

<p>We're looking for a Perl developer with 2+ years of experience programming<br />
professionally to join our engineering team in central London, primarily to<br />
work on the Nestoria property search engine (<a href="http://www.nestoria.com">http://www.nestoria.com</a>)</p>

<p>Nestoria is a great product to work on. As a vertical search engine we work<br />
hard to solve many of the same problems as a larger search company:</p>

<ul>
	<li>Reliably and quickly processing millions of listings</li>
	<li>Even more quickly searching those listings at query time</li>
	<li>Tracking user behaviour and always improving the user experience</li>
	<li>Internationalization - we work in eight countries with six languages</li>
	<li>Geocoding, Natural Language Processing, Image Processing, Historical, House Price Aggregation, Mobile Web...</li>
</ul>

<p><br />
We are looking for somebody who has:</p>

<ul>
	<li>2+ years' experience as a professional Perl programmer</li>
	<li>Strong knowledge of Perl best practices and modern Perl development practices</li>
	<li>Excellent technical communication skills</li>
	<li>A desire to coach, mentor and share your experience with junior team members</li>
</ul>

<p><br />
We're offering c. £45K plus bonus.</p>

<p>If that sounds interesting to you check out the full job ad here:</p>

<p><a href="http://www.lokku.com/jobs/experienced-perl-developer.html">http://www.lokku.com/jobs/experienced-perl-developer.html</a></p>

<p>If you have any questions or if you'd like to apply please get in<br />
touch at <a href="mailto:perldeveloper@lokku.com">perldeveloper@lokku.com</a></p>

<p>I'll also be at the London.pm technical meet up this coming Tuesday if<br />
you'd like to catch me in person :-)</p>

<p>Thanks,</p>

<p>- Alex</p>]]>
        
    </content>
</entry>

<entry>
    <title>Debugging Memory Use in Perl - Help!</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/alex_balhatchet/2012/01/debugging-memory-use-in-perl---help.html" />
    <id>tag:blogs.perl.org,2012:/users/alex_balhatchet//92.2641</id>

    <published>2012-01-04T10:49:12Z</published>
    <updated>2012-01-04T10:54:10Z</updated>

    <summary>Hey, Cross-posting this from a Stack Overflow Question asked by a colleague. Some processes that run for multiple hours (ETL jobs) suddenly started consuming a lot more RAM than usual. Analysis of the changes in the relevant release is a...</summary>
    <author>
        <name>Alex Balhatchet</name>
        <uri>http://kaoru.slackwise.net</uri>
    </author>
    
    <category term="memoryprofilingoptimization" label="memory profiling optimization" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/alex_balhatchet/">
        <![CDATA[<p>Hey,</p>

<p>Cross-posting this from a <a href="http://stackoverflow.com/questions/8715611/can-i-use-dtrace-on-os-x-10-5-to-determine-which-of-my-perl-subs-is-causing-the">Stack Overflow Question asked by a colleague</a>.</p>

<blockquote><small>Some processes that run for multiple hours (ETL jobs) suddenly started consuming a lot more RAM than usual. Analysis of the changes in the relevant release is a slow and frustrating process. I am hoping to identify the culprit using more automated analysis.

<p>Our live environment is perl 5.14 on Debian squeeze.</p>

<p>I have access to lots of OS X 10.5 machines, though. Dtrace and perl seem to play together nicely on this platform. Seems that using dtrace on linux requires a boot more work. I am hoping that memory allocation patterns will be similar between our live system and a dev OS X system - or at least similar enough to help me find the origin of this new memory use.</p>

<p>This slide deck:</p>

<p><a href="https://dgl.cx/2011/01/dtrace-and-perl">https://dgl.cx/2011/01/dtrace-and-perl</a></p>

<p>shows how to use dtrace do show number of calls to malloc by perl sub. I am interested in tracking the total amount of memory that perl allocates while executing each sub over the lifetime of a process.</p>

<p>Any ideas on how this can be done?</small></blockquote></p>

<p>We make great use of NYTProf for profiling the speed of our processes, but unfortunately there doesn't seem  to be anything anywhere near that good for memory consumption.</p>

<p>Does anybody have any advice for "profiling" memory use in Perl?</p>

<p>Thanks!</p>]]>
        
    </content>
</entry>

<entry>
    <title>Faster Perl debugging through crazy tricks?</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/alex_balhatchet/2011/02/faster-perl-debugging-through-crazy-tricks.html" />
    <id>tag:blogs.perl.org,2011:/users/alex_balhatchet//92.1460</id>

    <published>2011-02-11T16:42:55Z</published>
    <updated>2011-02-11T16:51:19Z</updated>

    <summary>Hi all, I&apos;m at work right now, waiting for some code to run in the Perl Debugger and I got to thinking. Right now I&apos;ve set a break point and I&apos;ve hit &quot;c&quot; for continue executing, and in the background...</summary>
    <author>
        <name>Alex Balhatchet</name>
        <uri>http://kaoru.slackwise.net</uri>
    </author>
    
    <category term="perldebugging" label="perl debugging" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/alex_balhatchet/">
        <![CDATA[<p>Hi all,</p>

<p>I'm at work right now, waiting for some code to run in the Perl Debugger and I got to thinking. Right now I've set a break point and I've hit "c" for continue executing, and in the background the debugger is doing all these checks on every single line and slowing down the execution of my program like crazy. I know it's doing <em>something</em> because if I hit ^C is halts properly at its current point of execution. What if there were some way to speed this up?</p>

<p>I'm thinking...</p>

<pre><code>DB > b $condition
DB > $DB::breakpoints_only_mode = 1;
DB > c</code></pre>

<p>Setting $DB::breakpoints_only_mode essentially promises the debugger that you won't hit ^C or anything silly like that. The implementation would be something like...</p>

<ul>
	<li>Set up a hook of some kind for all existing breakpoints, which turns debugger flags on, then checks the breakpoint, then turns debugger flags back off again.</li>
	<li>Turn off the debugger flag(s?)</li>
	<li>Continue running the code as normal</li>
</ul>

<p>What do Smarter People Than Me think of this idea?</p>

<p>(of course it's entirely possible that the debugger isn't actually slowing down my code all that much... but it feels like it is?)</p>]]>
        
    </content>
</entry>

<entry>
    <title>Introduction to wirting readable and maintainable Perl</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/alex_balhatchet/2011/02/introduction-to-wirting-readable-and-maintainable-perl.html" />
    <id>tag:blogs.perl.org,2011:/users/alex_balhatchet//92.1436</id>

    <published>2011-02-07T10:24:07Z</published>
    <updated>2011-02-11T16:36:36Z</updated>

    <summary>Hey all, I just got back from FOSDEM 2011 last night and had an absolute blast, especially on Sunday when I spent the whole day in the Perl devroom. Thanks to everyone who came! I gave a talk called Introduction...</summary>
    <author>
        <name>Alex Balhatchet</name>
        <uri>http://kaoru.slackwise.net</uri>
    </author>
    
    <category term="fosdem" label="fosdem" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="maintainable" label="maintainable" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="presentation" label="presentation" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="readable" label="readable" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="slides" label="slides" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/alex_balhatchet/">
        <![CDATA[<p>Hey all,</p>

<p>I just got back from FOSDEM 2011 last night and had an absolute blast, especially on Sunday when I spent the whole day in the Perl devroom. Thanks to everyone who came!</p>

<p>I gave a talk called <strong>Introduction to writing readable and maintainable Perl</strong> and I thought I'd share my slides here.</p>

<p><a href="http://www.slideshare.net/kaokun/introduction-to-writing-readable-and-maintainable-perl">http://www.slideshare.net/kaokun/introduction-to-writing-readable-and-maintainable-perl</a></p>

<p>Unfortunately Google Docs => PDF => Slideshare isn't an entirely flawless reproduction, but most of the slides look ok.</p>

<p>I'm considering giving an updated version of the talk at YAPC::EU this year. If you have any feedback please leave a comment or send me an email :)</p>

<p>- Alex</p>]]>
        
    </content>
</entry>

<entry>
    <title>highlight.pl</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/alex_balhatchet/2009/11/highlightpl.html" />
    <id>tag:blogs.perl.org,2009:/users/alex_balhatchet//92.48</id>

    <published>2009-11-26T12:06:53Z</published>
    <updated>2009-11-26T12:27:03Z</updated>

    <summary>This is a script I&apos;ve wanted to share for a while, but I haven&apos;t yet had the chance to figure out how to write App::Highlight (if anybody could give me some pointers in this direction it would be much appreciated!)...</summary>
    <author>
        <name>Alex Balhatchet</name>
        <uri>http://kaoru.slackwise.net</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/alex_balhatchet/">
        <![CDATA[<p>This is a script I've wanted to share for a while, but I haven't yet had the chance to figure out how to write App::Highlight (if anybody could give me some pointers in this direction it would be much appreciated!)</p>

<p>highlight.pl is designed to be piped into, like grep or ack, but instead of filtering out lines which don't match it just highlights words which do, similar to "ack --passthru" except that you get different coloured highlights for your different matches.</p>

<pre><code>
#!/usr/bin/perl

<p>#<br />
# pipe text to highlight.pl to highlight certain words<br />
#<br />
# eg. cat nastyfile.pl | highlight words you want<br />
#</p>

<p>use strict;<br />
use warnings;</p>

<p>use Term::ANSIColor qw/:constants/;<br />
use Getopt::Long;</p>

<p>my ($no_escape,$full_line);<br />
GetOptions(<br />
    'no-escape|n' => \$no_escape,<br />
    'full-line|l' => \$full_line,<br />
    'help|h'      => sub { print usage(); exit 0 },<br />
);</p>

<p>my @matches = (".+");<br />
if (scalar @ARGV) {<br />
    if ($no_escape) {<br />
        @matches = @ARGV;<br />
    }<br />
    elsif ($full_line) {<br />
        @matches = map { qr/^.*\Q$_\E.*$/ } @ARGV;<br />
    }<br />
    else {<br />
        @matches = map { "\Q$_" } @ARGV;<br />
    }<br />
}</p>

<p>my @colors = map { BOLD $_ } (<br />
RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN<br />
);</p>

<p>my $reset = RESET;</p>

<p>while (<STDIN>) {<br />
    my $i = 0;<br />
    foreach my $m (@matches) {<br />
        s/($m)/$colors[$i] . $1 . $reset/ge;</p>

<p>        $i++; $i %= @colors;<br />
    }<br />
    print;<br />
}</p>

<p>exit 0;</p>

<p>##########################################</p>

<p>sub usage {<br />
    return <<"    END";<br />
$0<br />
    --no-escape [n]     don't autoescape input, for using regular expressions<br />
    --full-line [l]     highlight the entire line that contains the match<br />
    --help      [h]     show this message<br />
    END<br />
}<br />
</code></pre></p>

<p>As a bonus, here's an alias I find very useful:</p>

<pre><code>
alias svndiff="svn diff | highlight -n '^[-][^-].*$' '^[+][^+].*$' '^(([-+]{2,})|([=]{5,})).+'"
</code></pre>

<p>This highlights filename headers in yellow, added lines in green and deleted lines in red.</p>

<p>Feedback welcome :) This is the first time I'm showing this code so it's probably very rusty and inefficient (I just noticed that svndiff would be simpler to write if --full-line and --no-escape worked together!)</p>

<p>- Alex</p>]]>
        
    </content>
</entry>

</feed>
