Compiling a package into a namespace

Simon Wistow simon at thegestalt.org
Mon Apr 14 20:42:57 BST 2008


On Fri, Apr 11, 2008 at 08:03:30PM +0100, Dave Cantrell said:
> It's more a case of "you're not telling us enough" :-)

You're right. And as such I will explain, just in case any one still 
cares.

So, I'm playing around with a super simple framework. it's not even a 
framework really more a sort of 'better' PHP. It's called Fiasco and 
some ideas which I wrote about it (slightly out of date but you get the 
gist) are here

  http://thegestalt.org/simon/using_fiasco.txt

So, what I want to do is have a directory that lies under the arbitary 
path

	/home/foo/myapp

in that directory is a tree that looks like

   `
    |-- a.pm
    |-- b.pm
    |-- c
        `-- b.pm
    
And when you call /myapp/a.html then a.pm gets called. Similarly with 
/myapp/b.html or /myapp/c/b.html

Now this doable if I force namespaces but I'd really rather not do that. 
Also, you may have noticed that there are two 'b's I'd really like it if 
there was no package in c/b.pm because then someone could really easily 
just do

	mv c d

and then 

	/myapp/d/b.html

would just work.

However then you have some odd problems if you want to inherit 

I'm sort of leaning towards maybe having a sort of mini DSL or helper 
functions that do the loading and the name frobbing for you. Actually 
what I'd really like is some way of making it *not* look like a Perl 
package so that you'd do this slightly contrived example


% cat c/b.pm
# load a normal Perl modules
use(DBI);
# inherit from centrally installed Perl module
is('Fiasco::Authenticated');
# inherit from the base previous 'b' down the directory tree
is('b'); 
# inherit from a specific module on another branch
is('d/e');

# do some stuff

# Helper is some utility functions that aren't meant to be seen
my $helper = class('helper');
my @stuff  = $helper->load_stuff;

# $this is automatically 
my $user   = $this->user;
return { stuff => [@stuff], user => $user };
% 

but it's possible that just going too far.




More information about the london.pm mailing list