File Coverage

blib/lib/App/Zealc.pm
Criterion Covered Total %
statement 25 27 92.5
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 34 36 94.4


line stmt bran cond sub pod time code
1             package App::Zealc;
2              
3 1     1   15010 use 5.014000;
  1         2  
  1         30  
4 1     1   4 use strict;
  1         1  
  1         28  
5 1     1   4 use warnings;
  1         3  
  1         56  
6              
7             our $VERSION = '0.000_001';
8              
9 1     1   516 use App::Cmd::Setup '-app';
  1         42123  
  1         6  
10 1     1   177 use parent qw/Class::Accessor::Fast/;
  1         1  
  1         5  
11             __PACKAGE__->mk_accessors(qw/path zeal config verbose/);
12              
13 1     1   4006 use Class::Method::Modifiers qw/before/;
  1         1658  
  1         69  
14 1     1   686 use Config::Auto;
  1         4863  
  1         29  
15              
16 1     1   6 use File::Spec::Functions qw/catfile/;
  1         1  
  1         42  
17              
18 1     1   219 use Zeal;
  0            
  0            
19              
20             use constant DEFAULT_PATH => $ENV{HOME} ? catfile $ENV{HOME}, '.docsets' : '.docsets';
21              
22             sub allow_any_unambiguous_abbrev () { 1 }
23             sub default_command { 'commands' } # Show usage when called without arguments
24              
25             sub global_opt_spec {
26             (['config|c=s' => 'Path to configuration file'],
27             ['path|p=s' => 'Path to docset directory',],
28             ['verbose|v!' => 'Print verbose debugging output'])
29             }
30              
31             sub parse_config {
32             my ($cfg) = @_;
33             return Config::Auto::parse($cfg) if $cfg;
34             eval { Config::Auto::parse } or {}
35             }
36              
37             before 'execute_command' => sub {
38             my ($self) = @_;
39             my %opts = %{$self->global_options};
40             my $config = parse_config $ENV{ZEALC_CONFIG} || $opts{config};
41             my %config = %$config;
42             my $path = $opts{path} || $config{path} || DEFAULT_PATH;
43             mkdir $path unless -d $path;
44              
45             my $zeal = Zeal->new($path);
46             $self->path($path);
47             $self->zeal($zeal);
48             $self->config($config);
49             $self->verbose($opts{verbose} || $config{verbose})
50             };
51              
52             1;
53             __END__