Archive for August, 2009

Private methods in Perl5

It is common knowledge that you can’t have private functions and methods in Perl5. But it turns out that you can do it, one way is to use namespace::clean. Using this module you can either declare all the names of private functions at the top or use a serie of non-obvious “use namespace::clean“, “no namespace::clean” calls.

Wouldn’t it be much nicer just to be able to write:


sub foo :Private {
    ...
}

You can, with my brand new Sub::Private module. It is actually quite simple:


use Attribute::Handlers;

use namespace::clean     qw();
use B::Hooks::EndOfScope qw(on_scope_end);
use Sub::Identify        qw(get_code_info);

sub UNIVERSAL::Private :ATTR(CODE,BEGIN) {
    my ($package, $symbol, $referent, $attr, $data) = @_;

    on_scope_end {
        namespace::clean->clean_subroutines( get_code_info( $referent ) );
    }
}

Putting the attribute handler in the UNIVERSAL namespace isn’t nice. I have to find a solution for that for the next version.

Comments (8)

Awesome is awesome!

At work I have a dual-head setup with two screens. Previously it seemed to me that you had to choose:

  • Either you could set the screens up as separate entities in xorg.conf, which means separate workspaces but not being able to move windows from one screen to the other
  • or you set it up as one big virtual screen with you workspace spanning both screens.

I like workspaces and use them a lot on my primary screen, but on my secondary screen I mostly want my browser and my instant messaging (IRC). Some solves this by making the windows on the secondary screen sticky, so the appears on every workspace. That doesn’t work for me – I still want my worksapces on the secondary screen, I just want the workspaces to behave separately from the workspaces on the primary screen.

For a long time I thought this impossible, so I used the first option with separate entries in my xorg.conf. I havn’t really missed moving windows from screen to screen, but Firefox is a bother. I want to be able to have Firefox windows on both screen without having to keep two profiles in sync.

Awesome3 to the rescue. I finally upgraded my window manager to awesome3 and after using xrandr to configure my screes, awesome works out of the box as I need. X only provides one display, which means that I can move windows freely around and Firefox can open windows on both screens, but Awesome automatically gives me separated workspaces on the two screens.

Of course I had do make some changes in the standard configuration for awesome. Other menus, click to focus (remove the awful.hooks.mouse_enter.register call), enforce floating layout with a proper window placement (some changes in the awful.hooks.manage.register call). View my configuration on GitHub Gists.

Comments (1)

Regular Expressions: Beyond the fundamentals

At this years YAPC::EU I’m giving a talk about some of the more advanced features of regular expressions.

Slides are available at http://hacking.dk/talks/yapceu2009/ – There is a pretty regexp validating dates (including February 29th) in it!

Comments (2)