Beagle
view release on metacpan or search on metacpan
lib/Beagle/Handle.pm view on Meta::CPAN
package Beagle::Handle;
use Any::Moose;
use Lingua::EN::Inflect 'PL';
use Beagle::Util;
use Beagle::Backend;
has 'name' => (
isa => 'Str',
is => 'rw',
lazy => 1,
default => sub { root_name( $_[0]->root ) },
);
has 'drafts' => (
isa => 'Bool',
is => 'ro',
lazy => 1,
default => 1,
);
has 'trusted' => (
isa => 'Bool',
is => 'ro',
lazy => 1,
default => 0,
);
has 'backend' => (
isa => 'Beagle::Backend::base',
is => 'rw',
lazy => 1,
default => sub {
my $self = shift;
my $root = current_root();
return Beagle::Backend->new( root => $root, type => root_type($root) );
},
handles => [qw/type root/],
);
has 'cache' => (
isa => 'Str',
is => 'ro',
lazy => 1,
default => sub {
my $self = shift;
my $name = $self->name;
my $file =
encode( locale_fs =>
catfile( cache_root(), $name . ( $self->drafts ? '.drafts' : '' ) )
);
my $parent = parent_dir($file);
make_path( $parent ) unless -e $parent;
return $file;
},
);
has 'info' => (
isa => 'Beagle::Model::Info',
is => 'rw',
handles => ['sites'],
);
my $type_info = entry_type_info();
for my $type ( keys %$type_info ) {
my $pl = $type_info->{$type}{plural};
my $class = $type_info->{$type}{class};
has $pl => (
isa => "ArrayRef[$class]",
is => 'rw',
default => sub { [] },
$type ne 'comment'
? (
trigger => sub {
my $self = shift;
$self->_init_entries;
}
)
: (),
);
}
has 'entries' => (
isa => 'ArrayRef[Beagle::Model::Entry]',
is => 'rw',
default => sub { [] },
);
has 'map' => (
isa => 'HashRef[Beagle::Model::Entry]',
is => 'rw',
default => sub { {} },
lazy => 1,
);
has 'attachments_map' => (
isa => 'HashRef',
is => 'rw',
default => sub { {} },
lazy => 1,
);
has 'comments_map' => (
isa => 'HashRef',
is => 'rw',
default => sub { {} },
lazy => 1,
);
( run in 0.921 second using v1.01-cache-2.11-cpan-ceb78f64989 )