I may be about to commit crimes against CPAN

Matt S Trout dbix-class at trout.me.uk
Fri Mar 21 21:41:34 GMT 2008


On Thu, Mar 13, 2008 at 07:55:00PM +0000, Simon Wistow wrote:
> So, I've been pondering writing YA XML module. Actually, I hacked up the 
> basis over an hour or so yesterday evening just to see if the idea 
> worked.
> 
> Essentially you define a class per element you may receive so
> 
> http://code.google.com/apis/gdata/elements.html#gdComments
> 
> might be translated into 
> 
> package gdComments;
> use strict;
> use base qw(XML::Declare::Element);
> 
> sub name      { "comments" }
> sub namespace { gd => 'http://schemas.google.com/g/2005' }
> 
> __PACKAGE__->attributes((
>     rel => {
>         type     => 'xs:string',
>         enum     => [ map { "http://schemas.google.com/g/2005#$_" } 
>                     qw(regular reviews) ],
>         optional => 1,
>     },
> ));
> 
> __PACKAGE__->elements((
>     feedLink => {
>         type     => 'gdFeedLink',
>     },
> ));
> 
> 1;
> 
> 
> or similar. gdFeedlink is another module. Then you do
> 
> my $comments = gdComments->new;
> $comments->rel("http://schemas.google.com/g/2005#regular");
> my $feedlink = gdFeedLink->new;
> $feedlink->countHint(1);
> $feedlink->href("http://example.com");
> 
> print "Before:\n".$comments->to_string."\n\n";
> $comments->feedLink($feedlink);
> print "After:\n".$comments->to_string."\n\n";
> 
> attributes have types (string, uri, boolean, integer) and can have 
> enums. I'm pondering changing things so that attributes and child 
> elements don't get automatically generated accessors and instead you 
> have to use 
> 
> 	->set($name, $value) 
> 
> or similar instead. 
> 
> Parsing and stringification is done via factories. At the moment I have 
> a ghetto hacked up thing that does it all with strings but 
> writing a XML::SAX or a XML::LibXML Factory would be really easy. In 
> fact, it occurs to me that writing a YAML and/or JSON Factory would be 
> easy too. Maybe I should call it Data::Declare instead.
> 
> So, anyway - it was fun to hack it up to this state and see if the proof 
> of concept works but I can't decide whether to just drop it now or if 
> it's at all useful.

I'd love to see something that used XML::Compile output to put together
Moose classes.

I'm not sure this is something that would support that or not though.

Beware of being too general with this though, once you stop being XML all
you're really doing is Yet Another Typed Object Systems AFAICS and Moose,
Class::Meta, etc. have already covered most of the possible wheel
permutations.

Also, you may wish to poke at ovid's Bermuda, which approaches a similar set
of problems from a different angle.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/


More information about the london.pm mailing list