]>
Commit | Line | Data |
---|---|---|
1 | package App::Zealc; | |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | ||
7 | our $VERSION = '0.000_001'; | |
8 | ||
9 | use App::Cmd::Setup '-app'; | |
10 | use parent qw/Class::Accessor::Fast/; | |
11 | __PACKAGE__->mk_accessors(qw/path zeal config verbose/); | |
12 | ||
13 | use Class::Method::Modifiers qw/before/; | |
14 | use Config::Auto; | |
15 | ||
16 | use File::Spec::Functions qw/catfile/; | |
17 | ||
18 | use Zeal; | |
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__ | |
54 | ||
55 | =encoding utf-8 | |
56 | ||
57 | =head1 NAME | |
58 | ||
59 | App::Zealc - command-line offline documentation browser for Dash/Zeal docsets | |
60 | ||
61 | =head1 SYNOPSIS | |
62 | ||
63 | use App::Zealc; | |
64 | App::Zealc->run; | |
65 | ||
66 | =head1 DESCRIPTION | |
67 | ||
68 | zealc is a command-line offline documentation browser inspired by | |
69 | L<Dash|http://kapeli.com/dash> and L<Zeal|http://zealdocs.org>. It | |
70 | uses Dash/Zeal format docsets via the L<Zeal> library. | |
71 | ||
72 | =head1 SEE ALSO | |
73 | ||
74 | L<zealc>, L<Zeal> | |
75 | ||
76 | =head1 AUTHOR | |
77 | ||
78 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> | |
79 | ||
80 | =head1 COPYRIGHT AND LICENSE | |
81 | ||
82 | Copyright (C) 2015 by Marius Gavrilescu | |
83 | ||
84 | This library is free software; you can redistribute it and/or modify | |
85 | it under the same terms as Perl itself, either Perl version 5.20.1 or, | |
86 | at your option, any later version of Perl 5 you may have available. | |
87 | ||
88 | ||
89 | =cut |