App-CSE

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

generated_by: 'Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: App-CSE
requires:
  Carp: '0'
  Class::InsideOut: '0'
  Class::Load: '0'
  DateTime: '0'
  Encode: '0'
  File::BaseDir: '0'
  File::Find: '0'
  File::MimeInfo::Magic: '0'
  File::Slurp: '0'
  File::stat: '0'
  Filesys::Notify::Simple: '0'
  Getopt::Long: '0'
  IO::Interactive: '0'
  JSON: '0'

Makefile.PL  view on Meta::CPAN

  "DISTNAME" => "App-CSE",
  "EXE_FILES" => [
    "bin/cse"
  ],
  "LICENSE" => "perl",
  "NAME" => "App::CSE",
  "PREREQ_PM" => {
    "Carp" => 0,
    "Class::InsideOut" => 0,
    "Class::Load" => 0,
    "DateTime" => 0,
    "Encode" => 0,
    "File::BaseDir" => 0,
    "File::Find" => 0,
    "File::MimeInfo::Magic" => 0,
    "File::Slurp" => 0,
    "File::stat" => 0,
    "Filesys::Notify::Simple" => 0,
    "Getopt::Long" => 0,
    "IO::Interactive" => 0,
    "JSON" => 0,

Makefile.PL  view on Meta::CPAN

    "TESTS" => "t/*.t t/toindex/perl/*.t"
  }
);


my %FallbackPrereqs = (
  "Carp" => 0,
  "Carp::Always" => 0,
  "Class::InsideOut" => 0,
  "Class::Load" => 0,
  "DateTime" => 0,
  "Encode" => 0,
  "File::BaseDir" => 0,
  "File::Copy::Recursive" => 0,
  "File::Find" => 0,
  "File::MimeInfo::Magic" => 0,
  "File::Slurp" => 0,
  "File::Temp" => 0,
  "File::stat" => 0,
  "Filesys::Notify::Simple" => 0,
  "Getopt::Long" => 0,

cpanfile  view on Meta::CPAN

requires 'Carp';
requires 'Class::InsideOut';
requires 'Class::Load';
requires 'DateTime';
requires 'Encode';
requires 'File::BaseDir';
requires 'File::Find';
requires 'File::MimeInfo::Magic';
requires 'File::Slurp';
requires 'File::stat';
requires 'Filesys::Notify::Simple';
requires 'Getopt::Long';
requires 'IO::Interactive';
requires 'JSON';

lib/App/CSE.pm  view on Meta::CPAN

}
use strict;
use warnings;
package App::CSE;
$App::CSE::VERSION = '0.016';

use Moose;
use Class::Load;
use Cwd;
use App::CSE::Colorizer;
use DateTime;
use File::MimeInfo::Magic;
use IO::Interactive;
use JSON;
use String::CamelCase;

use Path::Class::Dir;
use File::stat;
use Getopt::Long qw//;
use Regexp::Assemble;
use Text::Glob;

lib/App/CSE.pm  view on Meta::CPAN

has 'options_specs' => ( is => 'ro' , isa => 'ArrayRef[Str]', lazy_build => 1);

# The options as slurped by getopts long
has 'options' => ( is => 'ro' , isa => 'HashRef[Str]', lazy_build => 1);

# The arguments after any option
has 'args' => ( is => 'ro' , isa => 'ArrayRef[Str]', lazy_build => 1);


has 'index_dir' => ( is => 'ro' , isa => 'Path::Class::Dir', lazy_build => 1);
has 'index_mtime' => ( is => 'ro' , isa => 'DateTime' , lazy_build => 1);
has 'index_dirty_file' => ( is => 'ro' , isa => 'Path::Class::File', lazy_build => 1);
has 'dirty_files' => ( is => 'ro', isa => 'HashRef[Str]', lazy_build => 1);

has 'index_meta_file' => ( is => 'ro' , isa => 'Path::Class::File' , lazy_build => 1);
has 'index_meta' => ( is => 'ro', isa => 'HashRef[Str]', lazy_build => 1);

# File utilities
has 'xml_parser' => ( is => 'ro' , isa => 'XML::LibXML', lazy_build => 1);

# Environment slurping

lib/App/CSE.pm  view on Meta::CPAN

  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

                     follow => 0,
                   }, $dir_index );

  $indexer->commit();
  $PROGRESS_BAR->update($ESTIMATED_SIZE);


  rmtree $cse->index_dir()->stringify();
  rename $index_dir , $self->cse->index_dir()->stringify();

  $self->cse->index_meta->{index_time} = DateTime->now()->iso8601();
  # Also inject the right version
  $self->cse->index_meta->{version} = $self->cse->version();;

  $self->cse->save_index_meta();

  my $END_TIME = Time::HiRes::time();

  $LOGGER->info($self->cse->colorizer->colored("Index is ".$self->cse()->index_dir()->stringify(), 'green bold'));
  $LOGGER->info("$NUM_INDEXED files ($TOTAL_SIZE Bytes) indexed in ".sprintf('%.03f', ( $END_TIME - $START_TIME )).' seconds');

lib/App/CSE/Command/Search.pm  view on Meta::CPAN

package App::CSE::Command::Search;
$App::CSE::Command::Search::VERSION = '0.016';
use Moose;
extends qw/App::CSE::Command/;

use App::CSE::Command::Check;
use App::CSE::Command::Index;
use App::CSE::Lucy::Highlight::Highlighter;
use App::CSE::Lucy::Search::QueryPrefix;
use DateTime;
use File::Find;
use File::MimeInfo::Magic;
use Log::Log4perl;
use Lucy::Analysis::RegexTokenizer;
use Lucy::Search::Hits;
use Lucy::Search::IndexSearcher;
use App::CSE::Lucy::Search::QueryParser;
use Lucy::Search::SortSpec;
use Lucy::Search::SortRule;
use Path::Class::Dir;

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/Command/Watch.pm  view on Meta::CPAN

  if( $direct_child ){
    waitpid($direct_child , 0 );
    return 0;
  }

  my $pid = fork();
  confess("Cannot fork() a worker child: $!") unless defined $pid;

  if( $pid ){
    $cse->index_meta()->{'watcher.pid'} = $pid;
    $cse->index_meta()->{'watcher.started'} = DateTime->now()->iso8601();
    $cse->save_index_meta();
    $LOGGER->info(&$colored("PID=$pid :  Watching for changes in ".$self->dir_index().", updating ".$cse->index_dir(), "green bold"));
    exit(0);
  }

  my $deamon_log = q|log4perl.rootLogger                = INFO, SYSLOG
log4perl.appender.SYSLOG           = Log::Dispatch::Syslog
log4perl.appender.SYSLOG.min_level = debug
log4perl.appender.SYSLOG.ident     = cse V|.$cse->version().q|[|.$$.q|]
log4perl.appender.SYSLOG.facility  = daemon

lib/App/CSE/File.pm  view on Meta::CPAN

package App::CSE::File;
$App::CSE::File::VERSION = '0.016';
use Moose;

use App::CSE;
use Class::Load;
use Encode;
use File::Basename;
use File::Slurp;
use File::stat qw//;
use DateTime;
use String::CamelCase;

use Log::Log4perl;
my $LOGGER = Log::Log4perl->get_logger();

has 'cse' => ( is => 'ro' , isa => 'App::CSE' , required => 1 );

has 'mime_type' => ( is => 'ro', isa => 'Str', required => 1);
has 'file_path' => ( is => 'ro', isa => 'Str', required => 1);
has 'dir' => ( is => 'ro' , isa => 'Str' , required => 1, lazy_build => 1);

has 'encoding' => ( is => 'ro' , isa => 'Str', lazy_build => 1 );
has 'content' => ( is => 'ro' , isa => 'Maybe[Str]', required => 1, lazy_build => 1 );
has 'raw_content' => ( is => 'ro' , isa => 'Maybe[Str]', required => 1 , lazy_build => 1);
has 'decl' => ( is => 'ro' , isa => 'ArrayRef[Str]' , lazy_build => 1);
has 'call' => ( is => 'ro' , isa => 'ArrayRef[Str]' , lazy_build => 1);

has 'stat' => ( is => 'ro' , isa => 'File::stat' , lazy_build => 1 );
has 'mtime' => ( is => 'ro' , isa => 'DateTime' , lazy_build => 1);

sub _build_decl{
  return [];
}

sub _build_call{
  return [];
}

sub _build_dir{

lib/App/CSE/File.pm  view on Meta::CPAN

  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{



( run in 0.432 second using v1.01-cache-2.11-cpan-05444aca049 )