| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | package Mail::Summary::Tools::CLI::Context; | ||
| 4 | use Moose; | ||
| 5 | |||
| 6 | use File::Save::Home (); | ||
| 7 | use Path::Class; | ||
| 8 | |||
| 9 | has homedir => ( | ||
| 10 | isa => "Path::Class::Dir", | ||
| 11 | is => "rw", | ||
| 12 | lazy => 1, | ||
| 13 | default => sub { Path::Class::dir($_[0]->find_homedir) }, | ||
| 14 | ); | ||
| 15 | |||
| 16 | has cache => ( | ||
| 17 | isa => "Object", | ||
| 18 | is => "rw", | ||
| 19 | lazy => 1, | ||
| 20 | default => sub { | ||
| 21 | my $self = shift; | ||
| 22 | $self->create_yamlcache($self->cache_storage); | ||
| 23 | }, | ||
| 24 | ); | ||
| 25 | |||
| 26 | has cache_storage => ( | ||
| 27 | isa => "Path::Class::File", | ||
| 28 | is => "rw", | ||
| 29 | lazy => 1, | ||
| 30 | default => sub { $_[0]->homedir->file("cache") }, | ||
| 31 | ); | ||
| 32 | |||
| 33 | has nntp_overviews => ( | ||
| 34 | isa => "Object", | ||
| 35 | is => "rw", | ||
| 36 | lazy => 1, | ||
| 37 | default => sub { | ||
| 38 | my $self = shift; | ||
| 39 | warn "loading " . $self->nntp_overview_storage; | ||
| 40 | $self->create_yamlcache($self->nntp_overview_storage); | ||
| 41 | }, | ||
| 42 | ); | ||
| 43 | |||
| 44 | has nntp_overview_storage=> ( | ||
| 45 | isa => "Path::Class::File", | ||
| 46 | is => "rw", | ||
| 47 | lazy => 1, | ||
| 48 | default => sub { $_[0]->homedir->file("nntp_overviews") }, | ||
| 49 | ); | ||
| 50 | |||
| 51 | sub find_homedir { | ||
| 52 | my $self = shift; | ||
| 53 | |||
| 54 | return File::Save::Home::make_subhome_directory( | ||
| 55 | File::Save::Home::get_subhome_directory_status(".mailsum"), | ||
| 56 | ); | ||
| 57 | } | ||
| 58 | |||
| 59 | sub create_yamlcache { | ||
| 60 | my ( $self, $path ) = @_; | ||
| 61 | |||
| 62 | require Mail::Summary::Tools::YAMLCache; | ||
| 63 | return Mail::Summary::Tools::YAMLCache->new( file => $path ); | ||
| 64 | } | ||
| 65 | |||
| 66 | __PACKAGE__; | ||
| 67 | |||
| 68 | __END__ |