What I learned from YAPC::Brasil

I had a great time at YAPC::Brasil, but I really only understood the talks that I was giving (mostly). As with any conference, though, the talks are the least part of the conference. I think we spent as much time on the town as in the conference room. That's where all the good stuff happens, anyway. Most of the stuff I learn about Perl doesn't come from the talks but the casual conversations I have.

Speaking to the non-english audience

Conferences can be tricky things for non-native speakers, whether as someone giving a talk or listening to a talk. The common language, Perl, can overcome this just showing the code. I just put code on the slides, and make the interesting bits a different color:

Free local guides

The best part of a Perl event in a foreign country is the free travel services you get. The locals know how to work the mass transit, which parts of the city you'll probably want to see, which parts of the city you should avoid, and perhaps most importantly, serve as translators. Not only can they tell you what's on the menu, but they can tell you what to order and which restaurant does it well (with plenty of discussion on regional differences). In Rio, that would be feijoada and escondidinho.

At Bar Ernesto, Breno explains how to properly eat feijoada

Going from North America, Europe, and Oceania is fairly easily since you can expect both sides to speak, or at least understand, English. Going to Asia and South America is a bit tougher. However, a few attendees will probably speak English. You might be a bit shy, but the conference adds a bit of structure to ease you into the situation.

On the first part of the Pão de Açúcar

POD2::PT_BR, and others

Being an English speaker, and mostly just that, I don't pay attention to the internationization efforts. I know that some of the core Perl documentation has been translated, but I didn't know that there was a way that I could provide translations of my own modules' documentation.

Recent versions of perldoc have a -L switch that lets me specify a locale, such as PT_BR:

perldoc -L PT_BR perlstyle

I could also set the PERLDOC_POD2 to 1 to pick up the locale settings, although this setting is undocumented.

There are several translation packs in the POD2 namespace on CPAN:

Any module can participate by inserting documentation into the appropriate POD2::* namespace. If I wanted to add Brazilizian documentation to my Tie::Cycle module, for instance, I'd create a POD2/PT_BR/Tie/Cycle.pod file in my distribution. The Pod file has no code, but perldoc will still find it.

A literal bird's eye view of Rio.

Data::Printer

I've been doing Perl for a long time, so I tend to use the things that existed years ago, such as Data::Dumper. Besides organizing YAPC::Brasil this year, Breno also created Data::Printer. Many of the features I like from other pretty printers show up in this module, and Breno writes about why he wrote it.

Normally, dumping a complex object makes a mess when I only need to inspect a few of its values:

use DateTime;
use Data::Printer;

my $date = DateTime->now;
p( $date );
Data::Dumper wants to make Perl data structures, but often I don't really care about that. The output of Data::Printer is easier to read, although I have redacted the long lists of methods:
DateTime  {
    public methods (134) : ...
    private methods (38) : ...
    internals: {
        formatter         undef,
        local_c           {
            day              10,
            day_of_quarter   41,
            day_of_week      4,
            day_of_year      314,
            hour             23,
            minute           30,
            month            11,
            quarter          4,
            second           37,
            year             2011
        },
        local_rd_days     734451,
        local_rd_secs     84637,
        locale            DateTime::Locale::en_US,
        offset_modifier   0,
        rd_nanosecs       0,
        tz                DateTime::TimeZone::UTC,
        utc_rd_days       734451,
        utc_rd_secs       84637,
        utc_year          2012
    }
}

I don't need to know all of that stuff about DateTime, though, so I can provide my own filter:

use DateTime;
use Data::Printer {
    filters => {
       'DateTime' => sub { "DateTime => $_[0]" },
    },
};

my $date = DateTime->now;
p( $date );

Now I don't see the internals mess:

DateTime => 2011-11-10T23:35:55

I can deparse subroutines:

use DateTime;
use Data::Printer {
	deparse => 1,
	};

my $sub = sub {
	my( $m, $n ) = @_;
	$m + $n;
	};

p( $sub );
\ sub {
        my($m, $n) = @_;
        $m + $n;
    }
A closure is a bit trickier:
use DateTime;
use Data::Printer {
	deparse => 1,
	};

my $sub = do {
	my( $offset ) = 6;
	sub {
		my( $m, $n ) = @_;
		$offset + $m + $n;
		};
	};

p( $sub );
I don't get to see the closed-over lexical variables:
\ sub {
        my($m, $n) = @_;
        $offset + $m + $n;
    }
But I can define my own printer for a code reference, modifying what I'd done in Enchant closures for better debugging output:
use DateTime;
use Data::Printer {
	filters => {
		CODE => sub {
			require B;
			my $ref = shift;
			my $gv = B::svref_2object($ref)->GV;
			my( $file, $line ) = map { $gv->$_() } qw(FILE LINE);

			require B::Deparse;
			my $deparse = B::Deparse->new;
			my $code = $deparse->coderef2text($ref);
			$code =~ s/{/{ # defined at $file line $line /;

			require PadWalker;
			my $hash = PadWalker::closed_over( $ref );

			my $string = sprintf "sub %s\n\n---variables---\n%s\n---",
      			$code,
				Data::Printer::p( $hash );
			},
		},
	};

my $sub = do {
	my( $offset ) = 6;
	sub {
		my( $m, $n ) = @_;
		$offset + $m + $n;
		};
	};

p( $sub );
Now I can see the variables:
\ sub { # defined at test.pl line 21 
    my($m, $n) = @_;
    $offset + $m + $n;
}

---variables---
{
    $offset   \ 6
}
---

2 Comments

use Data::Printer very interesting

Very cool and interesting read. make me feel like I was there. :)

Leave a comment

About brian d foy

user-pic I'm the author of Mastering Perl, and the co-author of Learning Perl (6th Edition), Intermediate Perl, Programming Perl (4th Edition) and Effective Perl Programming (2nd Edition).