nupfel/Web-API — pull request #14 by robn (2014-07-03 01:14:13+00:00)
Title: RFC: remove Mouse dependency, use Class::XSAccessor

Not for merge, just a PoC based on our discussion in #10.

The main change is that there's now no type constraints. I'm not sure how much of a problem that is in practice since it seems pretty unlikely that that you're ever going to want to change any of the fields after construction. I assume that they were only `rw` so that modifying the object after construction from `BUILD` would work. If that's the case, then `ro` accessors and `BUILDARGS` would probably better, but that's a client change. In any case, we could enforce type constraints in the constructor with a minimum of fuss. Doing it in the accessors is pretty much impossible when using `Class::XSAccessor`.

Client changes! Only one necessary - since its now a class, need to inherit `Web::API` instead of compose it. For Moo/Moose, that's replacing `with 'Web::API'` with `extends 'Web::API`. No other changes were necessary.

The "lazy build" methods `json`, `xml` and `agent` are a bit skanky. That's about as fast as I know how to make them in pure-Perl. I don't really think speed is a pressing concern here. But this is a prototype so it doesn't hurt to try it.

One little bug here: `user_agent` gets the wrong idea of `__PACKAGE__`. If its always going to be subclassed it could use `caller` instead. Or it could just default to Web::API, and you send your own in if you want something different. Its a bit of a bikeshed argument so lets not dwell on it.

What do you think? I'd much prefer something like this over maintaining separate Mouse and Moo versions.