PrePAN

Sign in to PrePAN

File::CachedURL A Moo role that handles local caching of a remote file (specified by URL)

Good

Synopsis

package MyClass;

use Moo;
with('File::CachedURL');

has '+uri' => (default => sub { return 'http://www.cpan.org/modules/06perms.txt'; } );
has '+basename' => (default => sub { return '06perms.txt'; });

Description

I've got an existing module on CPAN, PAUSE::Permissions, which grabs 06perms.txt, caches it locally, and gives you an interface to the data in the file.

I've created another module, PAUSE::Packages, which is a similar interface, but to 02packages.details.txt.

So I've switched over to Moo, and done the caching as a role. See also:

  • https://github.com/neilbowers/PAUSE-Packages
  • https://github.com/neilbowers/PAUSE-Permissions

None of these changes have been released to CPAN yet.

Questions:

  • Is there a better name? I thought about URL::LocalCopy, or similar, but none of the names I've come up with so far seem right. Should it be under Role::?
  • Is there an existing module / role that does this? I couldn't find one, but that doesn't mean there isn't one out there.
  • Is there a better way to approach this?

As I write this I see I need to change uri to url :-)

Comments

I like the idea of these modules. :)

Shouldn't basename return something based on what the URL is instead of hardcoding it?
From the name, I wouldn't have thought it to be Moo or a Role, so I think the name should reflect that somehow. There are some MooX::Role::* modules already.

FWIW, I don't see why it should be a role from the example you give.
Hmm, PrePAN doesn't notify you when someone leaves a comment ...

brian: yes, I thought the same thing, but was being lazy to get something running :-/

david: agree on it not being a role. @tobyink has suggested it be a type, but for at least the next release I'm leaning towards your suggested (via github).
On notifications: so I hadn't put my email address in *all* of the relevant boxes at github. Sigh.
I've dropped the idea of having this role, based on @dagolden's suggestions for simplifying my PAUSE::* classes.
Maybe drop it as a role, but keep the functionality somewhere. Where in the world are you Neil? David and I are both in New York and I have an idea for a PAUSE Workshop here.
Alas, I'm in the UK, about 40 miles west of London. A PAUSE workshop sounds good.

Please sign up to post a review.