App-CSE
view release on metacpan or search on metacpan
lib/App/CSE.pm view on Meta::CPAN
sub _build_dirty_files{
my ($self) = @_;
unless( -r $self->index_dirty_file() ){
return {};
}
return JSON::decode_json(File::Slurp::read_file($self->index_dirty_file().'' , { binmode => ':raw' }));
}
sub _build_index_mtime{
my ($self) = @_;
my $st = File::stat::stat($self->index_dir());
return DateTime->from_epoch( epoch => $st->mtime() );
}
sub _build_max_size{
my ($self) = @_;
return $self->options()->{max_size} || 1048576; # 1 MB default. This is the buffer size of File::Slurp
}
sub _build_index_dir{
my ($self) = @_;
lib/App/CSE/Command/Index.pm view on Meta::CPAN
},
on_skip => sub{
$File::Find::prune = 1;
return undef;
}
});
unless( $valid ){
return;
}
my $stat = File::stat::stat($file_name.'');
&$wrapped($file_name, $stat);
};
};
$LOGGER->info("Estimating size. Please wait");
my $ESTIMATED_SIZE = 0;
File::Find::find({ wanted => &$wanted_wrapper(sub{
my ($file_name, $stat) = @_;
lib/App/CSE/Command/Search.pm view on Meta::CPAN
my $highlighter = $self->highlighter();
$LOGGER->info(&$colored('Hits: '. $self->offset().' - '.( $self->offset() + $self->num() - 1).' of '.$hits->total_hits().' sorted by '.$self->sort_str(), 'green bold')."\n\n");
while ( my $hit = $hits->next ) {
my $excerpt = $highlighter->create_excerpt($hit);
my $star = '';
if( my $stat = File::stat::stat( $hit->{path} ) ){
if( $hit->{mtime} lt DateTime->from_epoch(epoch => $stat->mtime())->iso8601() ){
$star = &$colored('*' , 'red bold');
# Mark the file as dirty.
$self->cse()->dirty_files()->{$hit->{'path.raw'}} = 1;
}
}else{
# No stat. File is gone (consider dirty)
$star = &$colored('-' , 'red bold');
$self->cse()->dirty_files()->{$hit->{'path.raw'}} = 1;
}
lib/App/CSE/File.pm view on Meta::CPAN
return [];
}
sub _build_dir{
my ($self) = @_;
return File::Basename::dirname($self->file_path());
}
sub _build_stat{
my ($self) = @_;
return File::stat::stat($self->file_path());
}
sub _build_mtime{
my ($self) = @_;
return DateTime->from_epoch( epoch => $self->stat->mtime() );
}
sub _build_encoding{
my ($self) = @_;
## This is the default. Override that in specific file types
return 'UTF-8';
}
sub _build_raw_content{
my ($self) = @_;
if( $self->stat()->size() > $self->cse()->max_size() ){
return undef;
}
return scalar( File::Slurp::read_file($self->file_path(), binmode => ':raw') );
}
sub _build_content{
my ($self) = @_;
my $raw_content = $self->raw_content();
unless( defined($raw_content) ){ return undef; }
( run in 0.593 second using v1.01-cache-2.11-cpan-49f99fa48dc )