Mutually Recursive Types

Unlike C/C++, Ocaml does not allow you to have “forward declarations” of types. In other words, if you have a record type A that has an entry that of type B and type B has an entry of type A, you cannot forward declare B so that it is in scope for record type A. In code:

type A = { foo : B }

type B = Bar of A

To get around this limitation, Ocaml has “mutually recursive types” with the keyword “and”. Now, “and” is overloaded to work with mutually recursive functions as well. So, if you want to do this you can use “and” thusly:

type A = { foo : B }
and
B = Bar of A

There is one thing to notice here: B does not have a “type” keyword in front of it. This isn’t necessary because the idea of “type” crosses the “and” boundary. Sometimes, you get long chains of this which can look slightly odd but isn’t too much of a problem most times.

GraphViz2 V 1.01 uses Algorithm::Dependency in order to...

... in order to let you pass in an Algorithm::Dependency object directly to GraphViz2's dependency(data => $object) method.

A new demo - dependency.pl - shows how, using a hand-build class hierarchy corresponding the code in t/lib/*.

Also, a new class, GraphViz2::Parse::ISA can be given a class name as in create(class => 'Parent::Child::Grandchild', ignore => []).

A new demo - parse.isa.pl - shows how, using the real class hierarchy in t/lib/*.

The demo page has been updated.

See demos # 5 and # 8.

Smarter matching

Smartmatching is complicated. Anyone suggesting otherwise simply hasn't used it much. Something that appears to be as simple as when @array can have 5 rather different meanings depending on the value of $_, the two most important being «each element in @$_ matches the corresponding element in @array» and «$_ matches any of @array». This is madness. I believe there's a lot of value in being able to explicitly differentiate when list(@array) and when any(@array).

Hence Smart::Match. It's a module that does exactly that and more. Not only does it allow you to disambiguate smartmatches, it also allows you to use powerful new matches by using higher order matchers. For example it doesn't just allow you to match against string_length(4), but also string_length(even) or string_length(range(13,42)). This makes smartmatching a lot easier and saner than doing it raw.

Phenona Perl platform on the cloud

Phenona is acquired by Active state . I have not seen anyone mention this in their blog or in any other feeds that I have so mentioning it here in case you have not heard about it . It's built by a 15 year old and IMHO is a very good marketing material for an application built with perl.

Perl code refactoring

Dear LazyPerl,

Does anyone know of a module that can do Perl refactoring, perhaps a PPI based module? I've heard Padre can do Perl code refactoring, but looked through the distro and didn't see any interesting modules.

The goal here is to hand a module to a function, and have it come back refactored according to a Perl::Critic policy.

Hugs,

Phred

GraphViz2 is out - Supporting all options of Graphviz 2.23.6+!

Hi Folks

Yes, it's true, GraphViz2 1.00 has been uploaded to CPAN.

I finally agreed not to call it GraphViz, so all your old, now obsolete, code will continue to run.

You can bookmark the demo page.

Cheers
Ron

How perl compiles subs and methods

This was just added to perloptree.pod in B::C

Call a subroutine

subname(args...) =>

pushmark
    args ...
gv => *subname
entersub

Call a method

Here we have several combinations to define the package and the method name, either compile-time (static as constant string), or dynamic as GV (for the method name) or PADSV (package name).

method_named holds the method name as sv if known at compile time. If not gv (of the name) and method is used. The package name is at the top of the stack. A call stack is added with pushmark.

Static compile time package and method

Class->subname(args...) =>

Moose and Fatal Type Constraints

After some excellent feedback from the Moose list, I thought I could share with you an issue that I know others have been concerned about. What follows are my thoughts on the matter, but I'd very much like to hear advice from others.

Consider the following:

package Foo;
use Moose;

has 'some_value' => (
  is  => 'ro',
  isa => 'Int',
);

When somebody does this:

# value contains the string "No charge"
my $foo = Foo->new({ some_value => $value });

Statistics back online

It's taken a little while, but the CPAN Testers Statistics site is now back online. Due to an unfortunate corruption of the cached data file, the file has taken some considerable time to rebuild.

With over 12 million reports to get through, the memory consumption to try and record everything all at once is quite demanding, hence why it's been building a chunk at a time. At some point very soon, I will be revisiting the way the data is collated and stored in memory and how the statistics are calculated and processed to make it all more efficient. I also plan to make it much more easy to process the sections to enable continuation if any part fails in a single run.

Get Hacking on MetaCPAN in Just Minutes

One of the fun things about MetaCPAN is that we've split the project into two main parts: an API and a front end. What this means is that if you want to start pushing your code into http://beta.metacpan.org, you don't need to run a local copy of the API. You can just git clone the front end, install your dependencies and be on your way.

Install cpanminus if you don't already have it. Then:

git clone git://github.com/CPAN-API/metacpan-web.git
cd metacpan-web
cpanm Dist::Zilla
dzil listdeps | cpanm
twiggy lib/MetaCPAN/Web.pm -p 5001 -R lib -R templates -E development

Bitcoin: Money is a sign of poverty

Some of you may have heard of Bitcoin before. This would be true if you have been following the lulsec hack of the NHS. Lulsec accept bitcoin as a donation method. There have also been some concern from the US Senate about bitcoin.

So, please read the wikipedia article above for a quick intro to bitcoin before you read any further.

I am interested in bitcoin because I like the anonymous and p2p nature of the service. While I would describe myself as a “socialist”, I still believe that there are some things that are not the government’s business and sometimes I just want to be left alone to do what I want without interference in the form of government. Another incentive for me is the cryptographic nerd in me loves the idea that you can have a completely anonymous currency using computers to do it.

Heads up: Astro-satpass modifications

The Astro-satpass distribution contains classes to compute satellite position and visibility. If you are using it, please read on.

Recently Jaap Meijers wrote to me about some inconsistencies between the satellite visibility predictions provided by the Astro-satpass package and the predictions of the Heavens Above web site (http://www.heavens-above.com/). This led to the correction of a number of bugs relating to the reporting (or not) of marginal passes by the Astro::Coord::ECI::TLE pass() method. These changes are currently available as release 0.039_04 of the Astro-satpass package.

MacOSX German Emacs keys

I've tried now up to 4 different Emacs on my german MacBook Air, and finally it looks like I can manage. Aquamacs is the best so far.

  1. xemacs my first choice as I use it everywhere else. looks awful, intolerable

  2. emacs-23.3 from ports +x11 in various flavors. Tried for 3 months. Together with TextMate, Padre, and even Eclipse. Eclipse was best and fastest, but I want an emacs as everywhere else.

  3. emacs-23.3 +cocoa patch Tried for one month.

  4. Emacs.App from ports Native cocoa patch, but german keys do not work. At all. /Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs

  5. Aquamacs This is it! Like my XEmacs on Windows and emacs on unices. See also http://www.emacswiki.org/emacs/AquamacsFAQ#toc5 And with the following key settings I can finally type my programs.

.emacs

releasing to [remote] minicpan (preferably with Dist::Zilla)

Traditionally at $work 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 ("I \N{HEAVY BLACK HEART} Dist::Zilla"), so the desire for a real company darkpan has been increasing.

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

One advantage of using CPAN::Mini::Inject::Server is that you can run it as a designated user and anybody who has access to the server can post to it.

I got it running with this app.psgi:

YAPC::Europe talk slots stats

I've made a draft calculation of what we've got in talk proposal list regarding time limits.

There are 36*20 + 28*40 + 10*60 + 120 = 2560 minutes of submitted talks right now.

Out of those there should be 5*60 + 40 = 340 minutes of talks to be given in one thread, thus having 2200 minutes (37 hours) in parallel.

As we'd like to start not earlier than 10 a.m. and wrap up at 6 p.m., minus 1 hour lunch, minus about an hour for coffee breaks and breaks between talks we come to 6 hours of talks a day, minus 1.5 hour of those given in one thread (keynotes and lightning talks). Not counting an auction.

Thus we can have 4.5*3 = 13.5 hours of parallel talks during the three main days, which is 40.5 hours if we have three rooms, and 54 hours if we have four.

If every submitted talk is accepted, we already are able to fill three talk rooms for the whole conference.

In any words, as we have four rooms, we can still accept about 14 hours of talks without renting yet another room.

Submit a talk right now if you'd like to give it at YAPC::Europe in Riga!

Combining Syslog and DBI

Saw an interesting interaction today. The Sys::Syslog module makes use of fork to prevent a blocking write to the console. Unfortunately, this means that if you are connected to a database via DBI and try to log anything via syslog, you'll run the issue of the DBI handle being closed under you. Even the DBI property of InactiveDestroy cannot save you b/c of the fork being hidden in Sys::Syslog. Thanks to David E Wheeler for the DBI AutoInactiveDestroy attribute which saves the day!

VS2010 Is Too Old?

> cpan Win32::Console::ANSI

ANSI.xs(12) : fatal error C1189: #error : your SDK is too old... (see the README file in the distro)

Fix:
@Set INCLUDE=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include
@Set INCLUDE=%INCLUDE%;C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE

Perl Epigraphs

Many Perl release announcements included an epigraph, a short excerpt from a literary or other creative work, chosen by the pumpking or release manager. This file assembles the known list of epigraph for posterity, and also links to the release announcements in mailing list archives.

It's quite interesting to read through the epigraphs in epigraphs.pod - a small insight into the Perl pumpkings. How many epigraphs do you recognize?

Installing Local Perl And Libraries On Mac Book Snow Leopard

I recently installed Perl 5.14 on a new Mac Book running Snow Leopard so I thought I'd share my findings and experiences to save the next person doing this some time.

I started off by doing a search on Google for "install perl mac".
Hit number 1: Download Perl - www.perl.org http://www.perl.org/get.html

That suggests you have a perl already installed, which is currently perl 5.10, or you can use App::Perlbrew.

It wasn't quite that easy so I've documented below exactly what I did. I've given feedback to Leo Laporte who looks after http://xrl.us/installperlosx and who should be updating the instructions on the perl.org page. At that point something like "curl -L http://xrl.us/installperlosx | bash" will work.

one-liner for separating iCal events by category

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, Text::vFile, and Text::vFile::asData.

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.

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

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->new("cal-$n.txt", "w"))->print($e); $e = undef; } else { (defined($e) ? $e : $v) .= $_ } END { print $v }' outlook.ics > leftover.txt

Then a bit of verification:

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.