<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Randy Stauner</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/randy_stauner/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/randy_stauner//668</id>
    <updated>2011-09-05T00:22:53Z</updated>
    <subtitle>perl -C -E &apos;say&quot;i \x{2764} &quot;,($^X =~ m#([^/]+)$#)&apos;</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Shebangs with perlbrew aliases and EUMM (and without local::lib)</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/2011/09/shebangs-with-perlbrew-aliases-and-eumm-and-without-locallib.html" />
    <id>tag:blogs.perl.org,2011:/users/randy_stauner//668.2167</id>

    <published>2011-09-04T23:22:27Z</published>
    <updated>2011-09-05T00:22:53Z</updated>

    <summary>I wanted to comment on kevin spencer&apos;s perlbrew intro but my blabbering grew so long I chose to make a separate post instead. shebangs I used to use the #!/usr/bin/env perl trick for shebangs until (when reading about packaging executables...</summary>
    <author>
        <name>Randy Stauner</name>
        <uri>http://www.magnificent-tears.com</uri>
    </author>
    
    <category term="perlbrew" label="perlbrew" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="shebang" label="shebang" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/randy_stauner/">
        <![CDATA[<p>I wanted to comment on
<a href="http://kevinspencer.org/archives/2011/08/installing_your_own_perl.html">kevin spencer's perlbrew intro</a>
but my blabbering grew so long I chose to make a separate post instead.</p>

<h2>shebangs</h2>

<p>I used to use the <code>#!/usr/bin/env perl</code> trick for shebangs until (when reading about packaging executables with dists) I learned that <a href="https://metacpan.org/module/ExtUtils::MakeMaker"><code>ExtUtils::MakeMaker</code></a> (and <a href="https://metacpan.org/module/Module::Build"><code>Module::Build</code></a>) will automatically rewrite a full-path shebang to point to the interpreter used during install, but it specifically does not do this with the env trick.</p>

<p>I inadvertently combined 'env perl' with <a href="https://metacpan.org/module/local::lib"><code>local::lib</code></a> once and found that the script (reachable from my local::lib bin/) would die because I was trying to run a script in my path with a perl that didn't have that module installed (I must have switched perls in the meantime).</p>

<p>If the perl that installed the module is embedded in the script then calling it from the command line makes sure that it will be run by a perl that has the module installed (and has the same version that corresponds to the script using it).  So it seems better to me to use the full path and let EUMM rewrite it.</p>

<h2>tl;dr: use perlbrew alias to denote "current" version</h2>

<p>I typically use one perl as my main perl
and use a perlbrew alias to point to it:</p>

<p><code>perlbrew alias create perl-5.14.1 local</code></p>

<p>Then I can use</p>

<p><code>#!/home/rando/perl5/perlbrew/perls/local/bin/perl</code></p>

<p>for the shebang in all of my scripts.</p>

<p>Yeah, it's a little long, but I tab complete it or dump an env var rather than typing it out.
This way any scripts that are part of dists I release will get rewritten by EUMM upon install and any scripts that are just for my personal use work with my "current" favorite perl.</p>

<p>When 5.14.2 is released I will install it, reinstall the modules I use, and change my perlbrew alias to point to it.</p>

<p>Sometimes I also symlink <code>/usr/local/bin/perl</code> to my perlbrew alias
if I'm the only one on the machine or if perlbrew is in a location that is available to everyone (like /opt).</p>

<p>Then you can use the very common</p>

<p><code>#!/usr/local/bin/perl</code></p>

<p>which is shorter and easier to remember.</p>

<h2>perlbrew and cpan modules</h2>

<p>As a side note I do a <code>perlbrew switch</code> and use the <code>cpan</code> client to install modules directly into the perl lib dir (with the default <code>installdirs site</code> option) and I only use <code>local::lib</code> if I need to test a module with my system-provided perl.</p>

<p>That way (with modules installed relative to the perl that installed them) when you <code>perlbrew switch</code> if you haven't installed a module it's script won't even be found in your path.</p>

<p>If anyone has any points of contention or better suggestions, please share.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Maintenance on Text::VimColor by Geoff Richards (GEOFFR)</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/2011/07/maintenance-on-textvimcolor-by-geoff-richards-geoffr.html" />
    <id>tag:blogs.perl.org,2011:/users/randy_stauner//668.1976</id>

    <published>2011-07-15T22:30:56Z</published>
    <updated>2011-07-15T23:04:53Z</updated>

    <summary>I&apos;m interested in maintaining Text::VimColor authored by Geoff Richards (GEOFFR). Does anybody know Geoff? He hasn&apos;t uploaded to CPAN since 2006. I emailed him a few months ago (using 3 different addresses from his CPAN page) but never heard back....</summary>
    <author>
        <name>Randy Stauner</name>
        <uri>http://www.magnificent-tears.com</uri>
    </author>
    
    <category term="comaint" label="comaint" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="vim" label="vim" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/randy_stauner/">
        <![CDATA[<p>I'm interested in maintaining <a href="http://metacpan.org/release/Text-VimColor">Text::VimColor</a> authored by Geoff Richards (GEOFFR).</p>

<p>Does anybody know Geoff?</p>

<p>He hasn't uploaded to CPAN since 2006.</p>

<p>I emailed him a few months ago
(using 3 different addresses from his <a href="http://metacpan.org/author/GEOFFR">CPAN page</a>)
but never heard back.</p>

<p>I asked on IRC and it sounded like a couple of guys knew him but hadn't heard from him in a long time.</p>

<p>So this is my last attempt before emailing the module list and asking for comaint status.</p>

<p>Thanks!</p>
]]>
        

    </content>
</entry>

<entry>
    <title>cpan client tries to install non-existent version</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/2011/07/cpan-client-tries-to-install-non-existent-version.html" />
    <id>tag:blogs.perl.org,2011:/users/randy_stauner//668.1962</id>

    <published>2011-07-12T00:19:13Z</published>
    <updated>2011-07-12T00:28:45Z</updated>

    <summary>Ran into an issue today and wanted to share in case anybody else hits the problem. Using the good-old cpan client I found myself unable to install a module. It took me a while to track down the problem... I...</summary>
    <author>
        <name>Randy Stauner</name>
        <uri>http://www.magnificent-tears.com</uri>
    </author>
    
    <category term="cpan" label="cpan" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/randy_stauner/">
        <![CDATA[<p>Ran into an issue today and wanted to share in case anybody else hits the problem.</p>

<p>Using the good-old <code>cpan</code> client I found myself unable to install a module.
It took me a while to track down the problem...</p>

<p>I had <code>CPAN::SQLite</code> installed and that appears to have a bug
(which I filed as <a href="https://rt.cpan.org/Ticket/Display.html?id=69415&amp;results=fac39aaa6779ed71d5035b5da8c2ba52">RT 69415</a>):</p>

<p>If a greater version of a dist is removed from the CPAN,
CPAN::SQLite will fail to reindex the "current" (lesser) version,
which means the <code>cpan</code> client will spiral into a 404 loop and give up.</p>

<p>So if you try to install a module and <code>cpan</code> spews 404 errors for a different version than you're expecting, open up <code>~/.cpan/cpandb.sql</code> with <code>sqlite3</code> and delete that record with something like:</p>

<p><code>DELETE FROM dists WHERE dist_name = '?'</code></p>
]]>
        

    </content>
</entry>

<entry>
    <title>Weird perl bug fixed [7c2d9d0]</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/2011/07/weird-perl-bug-fixed-7c2d9d0.html" />
    <id>tag:blogs.perl.org,2011:/users/randy_stauner//668.1958</id>

    <published>2011-07-09T23:40:53Z</published>
    <updated>2011-07-09T23:48:07Z</updated>

    <summary>My previous post about a weird do-block bug I stumbled upon has been fixed as of 7c2d9d0, the day after I posted. I don&apos;t know if anybody saw this post or if it was a coincidence, but thanks! I love...</summary>
    <author>
        <name>Randy Stauner</name>
        <uri>http://www.magnificent-tears.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/randy_stauner/">
        <![CDATA[<p><a href="http://blogs.perl.org/users/randy_stauner/2011/06/perl-bug-weird-combination-of-do-local-and-something-else.html">My previous post</a> about a weird do-block bug I stumbled upon has been fixed as of <a href="http://perl5.git.perl.org/perl.git/commit/7c2d9d0">7c2d9d0</a>,
the day after I posted.  I don't know if anybody saw this post or if it was a coincidence, but thanks!</p>

<p>I love the comment:</p>

<blockquote>
  <p>Fix context propagation below return()</p>

<p>A.k.a. "RT #38809 strikes back".</p>
</blockquote>
]]>
        

    </content>
</entry>

<entry>
    <title>Perl bug?  Weird combination of do, local, and something else?</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/2011/06/perl-bug-weird-combination-of-do-local-and-something-else.html" />
    <id>tag:blogs.perl.org,2011:/users/randy_stauner//668.1906</id>

    <published>2011-06-26T21:33:28Z</published>
    <updated>2011-07-09T23:51:18Z</updated>

    <summary>UPDATE: This perl bug has been fixed I was writing some very simple unit tests last night and was baffled when one didn&apos;t work. The code was very simple, something I thought I had done hundreds of times: return do...</summary>
    <author>
        <name>Randy Stauner</name>
        <uri>http://www.magnificent-tears.com</uri>
    </author>
    
    <category term="bug" label="bug" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/randy_stauner/">
        <![CDATA[<p><strong>UPDATE</strong>: <a href="http://blogs.perl.org/users/randy_stauner/2011/07/weird-perl-bug-fixed-7c2d9d0.html">This perl bug has been fixed</a></p>

<p>I was writing some very simple unit tests last night and was baffled when one didn't work.
The code was very simple, something I thought I had done hundreds of times:</p>

<p><code>return do { local $/; $fh-&gt;getline }</code></p>

<p>But I stumbled upon some weird voodoo...
It's extra baffling to me considering <a href="http://blogs.perl.org/users/brian_d_foy/2011/06/does-do-given-work-right.html">this recent post/bug discovery by Brian D Foy</a>.</p>

<p>It's not the same thing, but it seems similar to me.
Unfortunately the commit that fixed Brian's <a href="http://rt.perl.org/rt3/Ticket/Display.html?id=93548">bug 93548</a> does not fix this one.</p>

<p>I refactored the problem down to a pretty small sub,
and am further baffled by the minor variations that cause the problem to go away.</p>

<p>Here is the script and the output from various perls...
Interestingly this test appears to include another bug that was fixed somewhere between 5.10 and 5.12...</p>

<script src="https://gist.github.com/1048051.js"> </script>

<noscript>
<pre>
<code>
# original weirdness: same result changing local to my and if(){} to bare {}
sub weird {
  my ($c) = @_;
  if( ref $c ){
    return (ref $c eq 'SCALAR' ? 't' : do { local $/; 'do'; });
  }
  return 'r';
}

# fix: no local, no my
sub no_vars_in_do {
  my ($c) = @_;
  if( ref $c ){
    return (ref $c eq 'SCALAR' ? 't' : do {           'do'; });
  }
  return 'r';
}

# fix: no superfluous return after the if block (which is true for all of our tests)
sub no_extra_return {
  my ($c) = @_;
  if( ref $c ){
    return (ref $c eq 'SCALAR' ? 't' : do { local $/; 'do'; });
  }
}

# fix: both if(true){} or bare {} cause problems, works without block
sub no_enclosing_block {
  my ($c) = @_;
    return (ref $c eq 'SCALAR' ? 't' : do { local $/; 'do'; });
  return 'r';
}

# fix: use constant true/false values instead of ref $c
sub any_bool {
  my ($c) = @_;
  if( 1 ){
    return (                 0 ? 't' : do { local $/; 'do'; });
  }
  return 'r';
}

my ($i, @subs) = qw( 0 no_vars_in_do no_extra_return no_enclosing_block weird );
printf "# perl %vd\n1..%d\n", $^V, 2 * @subs + 1;

# only run this sub once since we can't reach the 't' outcome
t(any_bool => any_arg => 1, 'do');

for my $s ( @subs ){
  t($s, SCALAR  => \'s' , 't' );
  t($s, other   => ['s'], 'do');
}

sub t {
  my ($sub, $name, $val, $exp) = @_;
  my $r = &$sub( $val );
  my $result = ((my $ok = $r eq $exp) ? '' : 'not ') . 'ok';
  printf "%s %d # %*s: %10s => '%s' %5s\n",
    $result, ++$i, 22 - length($result) - int($i/10), $sub, $name, $r, $ok?'':'!';
}

__END__

# perl 5.8.3
# perl 5.10.1
1..9
not ok 1 # any_bool: any_arg => '' !
ok 2 # no_vars_in_do: SCALAR => 't'
ok 3 # no_vars_in_do: other => 'do'
ok 4 # no_extra_return: SCALAR => 't'
ok 5 # no_extra_return: other => 'do'
ok 6 # no_enclosing_block: SCALAR => 't'
ok 7 # no_enclosing_block: other => 'do'
ok 8 # weird: SCALAR => 't'
not ok 9 # weird: other => '' !
# perl 5.12.3
# perl 5.14.0
# perl 5.15.0 (blead) (c08f093)
1..9
ok 1 # any_bool: any_arg => 'do'
ok 2 # no_vars_in_do: SCALAR => 't'
ok 3 # no_vars_in_do: other => 'do'
ok 4 # no_extra_return: SCALAR => 't'
ok 5 # no_extra_return: other => 'do'
ok 6 # no_enclosing_block: SCALAR => 't'
ok 7 # no_enclosing_block: other => 'do'
ok 8 # weird: SCALAR => 't'
not ok 9 # weird: other => '' !
</code>
</pre>
</noscript>

<p>Can anybody make sense of this?
Am I missing something?
Or is this a legitimate perl bug?</p>

<p><strong>UPDATE</strong>:
I should add that, in my original function,
I added a warning to the <code>getline</code> method on the object so that I could tell that it was in fact getting called (inside the do-block), but somehow <code>undef</code> was still being returned in the end.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Exploratory one-liners with less typing</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/2011/06/exploratory-one-liners-with-less-typing.html" />
    <id>tag:blogs.perl.org,2011:/users/randy_stauner//668.1889</id>

    <published>2011-06-22T23:21:04Z</published>
    <updated>2011-06-23T00:22:28Z</updated>

    <summary>Here&apos;s one for the &quot;stupid shell tricks&quot; category: I made myself a shell alias today to simplify the times when i want a quick view of how something works in perl: alias perl1=&apos;perl -MData::Dumper -MYAML::Any -MClass::Autouse=:superloader -E &quot;sub D(\$){ say...</summary>
    <author>
        <name>Randy Stauner</name>
        <uri>http://www.magnificent-tears.com</uri>
    </author>
    
    <category term="alias" label="alias" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="bash" label="bash" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="oneline" label="one-line" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="shell" label="shell" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/randy_stauner/">
        <![CDATA[<p>Here's one for the "stupid shell tricks" category:</p>

<p>I made myself a shell alias today to simplify the times when i want a quick view of how something works in perl:</p>

<pre><code>alias perl1='perl -MData::Dumper -MYAML::Any -MClass::Autouse=:superloader -E "sub D(\$){ say Dumper(shift) } sub Y(\$){ say Dump(shift) }"'
</code></pre>

<p>I'm not quite sure about the name,
and I may add more helper functions,
but a handy alias like this one allows me to type this at the shell:</p>

<pre><code>perl1 -E 'D [File::Spec-&gt;path]'
</code></pre>

<p>Instead of</p>

<pre><code>perl -MData::Dumper -MFile::Spec -E 'say Dumper( [File::Spec-&gt;path] )'
</code></pre>

<p>I don't have to type out <code>-MData::Dumper</code> and I can use <code>D</code> instead of <code>say Dumper()</code></p>

<p>Plus, thanks to <code>Class::Autouse</code> and it's <code>:superloader</code> import tag
I don't have to type out Module::Name ("File::Spec" for example) multiple times
just to get a quick glance at it's output.</p>

<p>I haven't decided yet if I want to just append " -E" to the alias.
That might get in the way if I want the "-n" or "-p" flags or multiple -E's or something...</p>

<p>Anyway... thought that was handy; Thought I'd share.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>releasing to [remote] minicpan (preferably with Dist::Zilla)</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/2011/06/releasing-to-minicpan.html" />
    <id>tag:blogs.perl.org,2011:/users/randy_stauner//668.1843</id>

    <published>2011-06-11T17:53:02Z</published>
    <updated>2011-06-13T14:51:57Z</updated>

    <summary>Traditionally at $work we do a git clone of our various repos and run the projects straight from the working directory, but lately I&apos;ve been moving towards the good habit of packaging small related components into their own dists (&quot;I...</summary>
    <author>
        <name>Randy Stauner</name>
        <uri>http://www.magnificent-tears.com</uri>
    </author>
    
    <category term="cpanminus" label="cpanminus" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="darkpan" label="darkpan" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="distzilla" label="dist-zilla" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="minicpan" label="minicpan" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/randy_stauner/">
        <![CDATA[<p>Traditionally at <code>$work</code> we do a git clone of our various repos and run the projects straight from the working directory, but lately I've been moving towards the good habit of packaging small related components into their own dists (<code>"I \N{HEAVY BLACK HEART} Dist::Zilla"</code>), so the desire for a real company darkpan has been increasing.</p>

<p>I have a combination minicpan/darkpan that (mostly) works right now using:</p>

<ul>
<li><a href="http://beta.metacpan.org/module/CPAN::Mini::Inject::Server">CPAN::Mini::Inject::Server</a></li>
<li><a href="http://beta.metacpan.org/module/CPAN::Mini::Inject::Remote">CPAN::Mini::Inject::Remote</a></li>
<li><a href="http://beta.metacpan.org/module/Dist::Zilla::Plugin::Inject">Dist::Zilla::Plugin::Inject</a></li>
</ul>

<p>One advantage of using <a href="http://beta.metacpan.org/module/CPAN::Mini::Inject::Server">CPAN::Mini::Inject::Server</a> is that you can run it as a designated user and anybody who has access to the server can post to it.</p>

<p>I got it running with this <code>app.psgi</code>:</p>

<pre><code>use CGI::Application::Emulate::PSGI;
use CPAN::Mini::Inject::Server::Dispatch;

CGI::Application::Emulate::PSGI-&gt;handler(sub {
  CPAN::Mini::Inject::Server::Dispatch-&gt;dispatch();
});
</code></pre>

<p>I tried <a href="http://beta.metacpan.org/module/CGI::Application::PSGI">CGI::Application::PSGI</a> and <a href="http://beta.metacpan.org/module/CGI::Application::Dispatch::PSGI">CGI::Application::Dispatch::PSGI</a> but wasn't able to get either of them working right (according to their synopses).  Third time's a charm.  Thanks, <a href="http://beta.metacpan.org/module/CGI::Application::Emulate::PSGI">CGI::Application::Emulate::PSGI</a>.</p>

<p>So I added the <a href="http://beta.metacpan.org/module/Dist::Zilla::Plugin::Inject">Inject</a> plugin to my <code>$work</code> <a href="http://beta.metacpan.org/module/Dist::Zilla">Dist::Zilla</a> bundle, set <code>remote_server</code> to <code>"http://localhost:7990/"</code> (arbitrary port) and set a fake <code>author_id</code>.</p>

<p>I telecommute, so I spend most of my work day with an open ssh connection to the office, so adding another port-forward to my present list was no trouble.  Obviously, your authentication method will be up to you.</p>

<p>If you don't use <a href="http://beta.metacpan.org/module/Dist::Zilla">Dist::Zilla</a>,
<a href="http://beta.metacpan.org/module/CPAN::Mini::Inject::Remote">CPAN::Mini::Inject::Remote</a> has a command line script (and an API) that you should be able to leverage for your situation.</p>

<h2><del>the issue</del> (if you don't update)</h2>

<p><del>The only problem I have with this setup is <a href="https://github.com/AndyA/CPAN--Mini--Inject/issues/2">an outstanding issue with CPAN::Mini::Inject</a>: injecting newer versions of your modules doesn't remove older versions from the list, so <a href="http://beta.metacpan.org/module/App::cpanminus">cpanminus</a> will find the first (oldest) version in the 02packages file and use that one.  The workaround is to update your minicpan mirror and then re-inject (you don't have to re-add).</del></p>

<h3>UPDATE (fixed)</h3>

<p><strong>CPAN::Mini::Inject 0.30 was released this morning which fixes the aforementioned issue.  Thanks go to Christian Walde and Paul Driver.  Hooray!</strong></p>

<h2>a new breed</h2>

<p>I'm very interested to see if chromatic's <a href="https://github.com/chromatic/CPAN-Dark">new Darkpan module</a> will be a more interesting or practical solution in this or other scenarios.  It may prove easier to keep 2 different PANs (one mini, one dark) up to date separately, and just add an extra <code>--mirror</code> argument to <code>cpanm</code>.
I'll have to play with that this week and I'll try to pass along any feedback.</p>

<p>A big thanks to all the authors of all the modules that work together to make this happen.  CPAN really is the happiest place on earth.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>one-liner for separating iCal events by category</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/2011/06/one-liner-for-separating-ical-events-by-category.html" />
    <id>tag:blogs.perl.org,2011:/users/randy_stauner//668.1835</id>

    <published>2011-06-07T17:33:58Z</published>
    <updated>2011-06-08T02:21:57Z</updated>

    <summary>Attempting to move a friend from Outlook to Google Calendar, we exported the calendar to an iCal file. I wanted to create separate Calendars for each event category. I searched cpan for modules to read the file and found iCal::Parser,...</summary>
    <author>
        <name>Randy Stauner</name>
        <uri>http://www.magnificent-tears.com</uri>
    </author>
    
    <category term="ical" label="ical" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="oneline" label="one-line" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="oneoff" label="one-off" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/randy_stauner/">
        <![CDATA[<p>Attempting to move a friend from Outlook to Google Calendar,
we exported the calendar to an iCal file.</p>

<p>I wanted to create separate Calendars for each event category.</p>

<p>I searched cpan for modules to read the file
and found iCal::Parser, Text::vFile, and Text::vFile::asData.</p>

<p>I really didn't need to parse the data,
because then I would have to figure out how to unparse it,
and i didn't want the data to get messed up in the process.</p>

<p>I was definitely justified:  simply doing <code>iCal::Parser-&gt;new-&gt;parse($file)</code> put my CPU at 3.5 load for 2+ minutes, whereas this one-liner takes a fraction of a second:</p>

<pre><code>perl  -MIO::File -nE 'if(/BEGIN:VEVENT/){ warn("event not ended: $e") if defined $e; $e = $_ } elsif(/END:VEVENT/){ $e .= $_; $e =~ /^CATEGORIES:\s*(.+)\s*$/m; ($n=$1||"")=~s/\W+/_/g; ($fh{$n} ||= IO::File-&gt;new("cal-$n.txt", "w"))-&gt;print($e); $e = undef; } else { (defined($e) ? $e : $v) .= $_ } END { print $v }' outlook.ics &gt; leftover.txt
</code></pre>

<p>Then a bit of verification:</p>

<pre><code>$ expr `wc -l &lt; outlook.ics` - `wc -l &lt; leftover.txt`
16604

$ cat cal* | wc -l
16604

$ diff &lt;(grep -h CATEGORIES cal* | sort | uniq -c) &lt;(grep -h CATEGORIES outlook.ics | sort | uniq -c)
</code></pre>

<p>Then I split <code>leftover.txt</code> manually because I don't know that much about the iCal format and don't know what other possibilities there might be, but the file I had was pretty straightforward... there was a 20 line header, and 1 line tail ("END:VCALENDAR"), and everything in between was events.</p>

<pre><code>$ for i in cal*; { cat head.txt $i tail.txt &gt; icals/${i%.txt}.ics; }
</code></pre>

<p>Now I have separate calendar files for each category.
Now, if only Google Calendar would let me upload them all at once and name them like I name my files... oh well.  I've gained enough already, I can do this part manually.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>CPAN::Reporter fails to send through Metabase with new LWP 6</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/randy_stauner/2011/03/cpanreporter-fails-to-send-through-metabase-with-new-lwp-6.html" />
    <id>tag:blogs.perl.org,2011:/users/randy_stauner//668.1537</id>

    <published>2011-03-09T14:43:24Z</published>
    <updated>2011-03-09T15:20:35Z</updated>

    <summary>I tweeted something last night knowing full well that few people see my tweets and most of those that do aren&apos;t programmers. So I decided to post here in case anyone else experienced the same problem. I installed the new...</summary>
    <author>
        <name>Randy Stauner</name>
        <uri>http://www.magnificent-tears.com</uri>
    </author>
    
    <category term="cpan" label="cpan" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="cpantesters" label="cpantesters" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="lwp" label="lwp" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="ssl" label="ssl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/randy_stauner/">
        <![CDATA[<p>I tweeted something last night knowing full well that few people see my tweets
and most of those that do aren't programmers.
So I decided to post here in case anyone else experienced the same problem.</p>

<p>I installed the new LWP (v6) last night via cpan.</p>

<p>The next time I tried to install a module my cpan client barfed red errors (see below).
<code>CPAN::Reporter</code> was erroring when trying to send test results via <code>Metabase</code>.</p>

<p>I updated all SSL modules (<code>cpan&gt; upgrade /SSL/</code>) and installed <code>Mozilla::CA</code>
as suggested in the <a href="http://search.cpan.org/src/GAAS/libwww-perl-6.00/Changes">LWP Changes</a>
(and <a href="http://twitter.com/#!/miyagawa/status/45204410103635968">a tweet by miyagawa</a>).</p>

<p>No luck.</p>

<p>I noticed something else in the LWP Changes file:</p>

<pre><code>For https://... default to verified connections with require IO::Socket::SSL
and Mozilla::CA modules to be installed.  Old behaviour can be requested by
setting the PERL_LWP_SSL_VERIFY_HOSTNAME environment variable to 0.  The
LWP::UserAgent got new ssl_opts method to control this as well.
</code></pre>

<p>so I added this to my <code>.bashrc</code> and all is well again:</p>

<pre><code>alias cpan='env PERL_LWP_SSL_VERIFY_HOSTNAME=0 cpan'
</code></pre>

<p>Not exactly a solution, but I'm ok with it for now.</p>

<p>(of course elsewhere in my <code>.bashrc</code> I have</p>

<pre><code>alias sudo='sudo '
</code></pre>

<p>so that when I do <code>sudo cpan</code> it expands aliases.</p>

<hr />

<p>So is this a module problem or is it a problem with cpantesters' certificate?</p>

<hr />

<p>Here are the errors I saw in case anyone is interested
(after installing LWP 6 I tried to reinstall the old 5.837 before I found a fix for the problem):</p>

<pre><code>CPAN::Reporter: Test result is 'pass', All tests successful.
CPAN::Reporter: preparing a CPAN Testers report for libwww-perl-5.837
CPAN::Reporter: sending test report with 'pass' via Metabase
CPAN::Reporter: Test::Reporter: error from 'Test::Reporter::Transport::Metabase:'
fact submission failed: Can't connect to metabase.cpantesters.org:443 (certificate verify failed) at /usr/local/share/perl/5.10.1/Metabase/Client/Simple.pm line 111
        Metabase::Client::Simple::submit_fact('Metabase::Client::Simple=HASH(0x94572a8)', 'CPAN::Testers::Report=HASH(0xa4d2778)') called at /usr/local/share/perl/5.10.1/Test/Reporter/Transport/Metabase.pm line 132
        Test::Reporter::Transport::Metabase::send('Test::Reporter::Transport::Metabase=HASH(0xa332920)', 'Test::Reporter=HASH(0x9eb3ce8)') called at /usr/local/share/perl/5.10.1/Test/Reporter.pm line 279
        eval {...} called at /usr/local/share/perl/5.10.1/Test/Reporter.pm line 279
        Test::Reporter::send('Test::Reporter=HASH(0x9eb3ce8)') called at /usr/local/share/perl/5.10.1/CPAN/Reporter.pm line 503
        CPAN::Reporter::_dispatch_report('HASH(0x9ec5c70)') called at /usr/local/share/perl/5.10.1/CPAN/Reporter.pm line 117
        CPAN::Reporter::grade_test('CPAN::Distribution=HASH(0x9153068)', '/usr/bin/make test', 'ARRAY(0x9f08748)', 0) called at /usr/local/share/perl/5.10.1/CPAN/Reporter.pm line 223
        CPAN::Reporter::test('CPAN::Distribution=HASH(0x9153068)', '/usr/bin/make test') called at /usr/local/share/perl/5.10.1/CPAN/Distribution.pm line 3242
        CPAN::Distribution::test('CPAN::Distribution=HASH(0x9153068)') called at /usr/local/share/perl/5.10.1/CPAN/Distribution.pm line 3464
        CPAN::Distribution::install('CPAN::Distribution=HASH(0x9153068)') called at /usr/local/share/perl/5.10.1/CPAN/Shell.pm line 1796
        CPAN::Shell::rematein('CPAN::Shell', 'install', 'GAAS/libwww-perl-5.837.tar.gz') called at /usr/local/share/perl/5.10.1/CPAN/Shell.pm line 1976
        CPAN::Shell::__ANON__('CPAN::Shell', 'GAAS/libwww-perl-5.837.tar.gz') called at /usr/local/share/perl/5.10.1/App/Cpan.pm line 459
        App::Cpan::__ANON__('GAAS/libwww-perl-5.837.tar.gz') called at /usr/local/share/perl/5.10.1/App/Cpan.pm line 468
        App::Cpan::_default('ARRAY(0x857d800)', 'HASH(0x8d68a58)') called at /usr/local/share/perl/5.10.1/App/Cpan.pm line 386
        App::Cpan::run('App::Cpan', 'GAAS/libwww-perl-5.837.tar.gz') called at /usr/local/bin/cpan line 11
</code></pre>
]]>
        

    </content>
</entry>

</feed>
