| 1 | package CHI::Driver::Reddit; | ||
| 2 | use Moo; | ||
| 3 | extends 'CHI::Driver'; | ||
| 4 | |||
| 5 | our $VERSION = 0.02; | ||
| 6 | |||
| 7 | sub BUILD { | ||
| 8 | my ($self, $args) = @_; | ||
| 9 | |||
| 10 | die 'requires username, password and subreddit arguments' | ||
| 11 | unless 3 == grep { $_ } map { $args->{$_} } qw/username password subreddit/; | ||
| 12 | |||
| 13 | $ENV{reddit_username} = $args->{username}; | ||
| 14 | $ENV{reddit_password} = $args->{password}; | ||
| 15 | $ENV{reddit_subreddit} = $args->{subreddit}; | ||
| 16 | |||
| 17 | require Cache::Reddit; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub store { Cache::Reddit::set($_[1]) } | ||
| 21 | |||
| 22 | sub fetch { Cache::Reddit::get($_[1]) } | ||
| 23 | |||
| 24 | sub clear { Cache::Reddit::remove($_[1]) } | ||
| 25 | |||
| 26 | 1; | ||
| 27 | =encoding utf8 | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | CHI::Driver::Reddit - use Reddit as a cache! | ||
| 32 | |||
| 33 | =head1 SYNOPSIS | ||
| 34 | |||
| 35 | use CHI; | ||
| 36 | my $cache = CHI->new( | ||
| 37 | subreddit => 'somesubreddit', # the subreddit to post to | ||
| 38 | username => 'foo', # reddit username | ||
| 39 | password => 'barbarbar', # reddit password | ||
| 40 | driver => 'Reddit', | ||
| 41 | ); | ||
| 42 | ... | ||
| 43 | |||
| 44 | =head1 DESCRIPTION | ||
| 45 | |||
| 46 | See L<Cache::Reddit> and L<CHI> for details. | ||
| 47 | |||
| 48 | =head1 AUTHOR | ||
| 49 | |||
| 50 | David Farrell | ||
| 51 | |||
| 52 | =head1 LICENSE | ||
| 53 | |||
| 54 | Two Clause FreeBSD, see LICENSE | ||
| 55 | |||
| 56 | E<copy> 2017, David Farrell | ||
| 57 | |||
| 58 | =cut |