Compiling a package into a namespace

Nicholas Clark nick at ccl4.org
Sat Apr 12 11:01:53 BST 2008


On Fri, Apr 11, 2008 at 03:56:47PM -0400, Jesse Vincent wrote:

> Following is an implementation of "qualified packages", which means  
> that each module (Test1 and Test2) can depend on different variant  
> ("Foo1" and "Foo2") of certain package ("Foo").

> use strict;
> BEGIN { $^P |= 0x01 }

This turns on the perl debugger. How painful is that performance wise?

> # The use case
> package Foo1; sub new { bless {}, 'Foo1' }
> package Foo2; sub new { bless {}, 'Foo2' }
> package Test1; sub t1 { Common->foo }
> package Test2; sub t2 { Common->foo }
> package Common; sub foo { Foo->new }
> 
> package main;
> warn Test1::t1(); # Foo1 object
> warn Test2::t2(); # Foo2 object

I keep wondering how this works with diamond inheritance.

Test1 isa Foo (using Foo1)
Test2 isa Foo (using Foo2)

Boom isa qw(Test1 Test2)

Boom->Foo() # who you gonna call?

Implementation wise, I think it's viable to do this in core if problems like
this can be solved, including compiling two versions of the same XS module
and loading them simultaneously.

It's not an itch I need to scratch, so I've not looked further.

Nicholas Clark


More information about the london.pm mailing list