App-CSE
view release on metacpan or search on metacpan
lib/App/CSE.pm view on Meta::CPAN
sub _build_ignore_reassembl{
my ($self) = @_;
my $re = Regexp::Assemble->new();
if( my $cseignore = $self->cseignore() ){
my @lines = split(q/\n/ , $cseignore->slurp());
foreach my $line ( @lines ){
if( $line =~ /^\s*(?:#|$)/ ){
next;
}
$line =~ s/^\s*//; $line =~ s/\s*$//;
$re->add( Text::Glob::glob_to_regex_string( $line ) );
}
}
return $re;
}
sub _build_xml_parser{
my ($self) = @_;
return XML::LibXML->new();
}
sub _build_colorizer{
my ($self) = @_;
return App::CSE::Colorizer->new( { cse => $self } );
}
sub _build_interactive{
my ($self) = @_;
return IO::Interactive::is_interactive();
}
sub _build_index_meta_file{
my ($self) = @_;
return $self->index_dir()->file('cse_meta.js');
}
sub _build_index_dirty_file{
my ($self) = @_;
return $self->index_dir()->file('cse_dirty.js');
}
sub _build_index_meta{
my ($self) = @_;
unless( -r $self->index_meta_file() ){
return { version => '-unknown-' };
}
return JSON::decode_json(File::Slurp::read_file($self->index_meta_file().'' , { binmode => ':raw' }));
}
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) = @_;
if( my $opt_idx = $self->options->{idx} ){
return Path::Class::Dir->new($opt_idx);
}
return Path::Class::Dir->new('.cse.idx');
}
sub _build_command_name{
my ($self) = @_;
unless( $ARGV[0] ){
return 'help';
}
if( $ARGV[0] =~ /^-/ ){
# The first argv is an option. Assume search
return 'search';
}
## Ok the first argv is a normal string.
## Attempt loading a command class.
my $command_class = eval{ Class::Load::load_class(__PACKAGE__.'::Command::'.String::CamelCase::camelize($ARGV[0])) };
if( $command_class ){
# Valid command class. Return it.
return shift @ARGV;
};
## This first word is not a valid commnad class.
## Assume search.
return 'search';
}
sub _build_command{
my ($self) = @_;
my $command_class = Class::Load::load_class(__PACKAGE__.'::Command::'.String::CamelCase::camelize($self->command_name()));
my $command = $command_class->new({ cse => $self });
return $command;
}
sub _build_options_specs{
my ($self) = @_;
return $self->command()->options_specs();
}
sub _build_options{
my ($self) = @_;
( run in 1.303 second using v1.01-cache-2.11-cpan-39bf76dae61 )