App-CSE
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/CSE.pm view on Meta::CPAN
=back
=head1 PROGRAMMATIC USAGE
In addition of using this via the command line program 'cse', you can use this app
in an object oriented way.
For instance:
my $app = App::CSE->new( { command_name => 'index',
options => { 'idx' => '/path/to/the/index' ,
'dir' => '/code/directory/to/index'
});
if( $app->execute() ){
.. and error occured ..
}else{
.. It is a success ..
}
Retrieving search hits after a search:
my $app = App::CSE->new( { command_name => 'search',
args => [ 'search_query' ],
options => { 'idx' => '/path/to/the/index' ,
'dir' => '/code/directory/to/index'
});
my $hits = $app->command()->hits();
# This is a L<Lucy::Search::Hits>
See L<App::CSE::Command::Help> for a list of available commands and options.
=head1 LOGGING
App::CSE uses L<Log::Log4perl>
=head1 BUILD STATUS
=begin html
<a href="https://travis-ci.org/jeteve/App-CSE"><img src="https://travis-ci.org/jeteve/App-CSE.svg?branch=master"></a>
=end html
=head1 COPYRIGHT
See L<App::CSE::Command::Help>
=cut
my $LOGGER = Log::Log4perl->get_logger();
has 'command_name' => ( is => 'ro', isa => 'Str', required => 1 , lazy_build => 1);
has 'command' => ( is => 'ro', isa => 'App::CSE::Command', lazy_build => 1);
has 'max_size' => ( is => 'ro' , isa => 'Int' , lazy_build => 1);
has 'interactive' => ( is => 'ro' , isa => 'Bool' , lazy_build => 1 );
has 'colorizer' => ( is => 'ro' , isa => 'App::CSE::Colorizer' , lazy_build => 1);
# GetOpt::Long options specs.
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
has 'cseignore' => ( is => 'ro', isa => 'Maybe[Path::Class::File]', lazy_build => 1 );
has 'ignore_reassembl' => ( is => 'ro', isa => 'Regexp::Assemble', lazy_build => 1);
{# Singleton flavour
my $instance;
sub BUILD{
my ($self) = @_;
$instance = $self;
}
sub instance{
return $instance;
}
}
sub _build_cseignore{
my ($self) = @_;
my $file = Path::Class::Dir->new()->file('.cseignore');
unless( -e $file ){
return;
}
$LOGGER->info("Will ignore patterns from '$file'");
return $file;
}
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();
}
view all matches for this distributionview release on metacpan - search on metacpan
( run in 8.709 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-f5108d614456 )