]>
iEval git - zeal.git/blob - lib/Zeal/Feed.pm
d51aebbf3c1983ab79eedc896f4cbb176e6a3369
8 our $VERSION = '0.000_003';
10 use parent qw
/Class::Accessor::Fast/;
11 __PACKAGE__
->mk_ro_accessors(qw
/version/);
14 use File
::Spec
::Functions qw
/catfile rel2abs/;
18 use File
::Slurp qw
/read_file/;
23 my ($class, $url) = @_;
24 $class->new_from_content(HTTP
::Tiny
->new->get($url)->{content
});
28 my ($class, $file) = @_;
29 $class->new_from_content(scalar read_file
$file);
32 sub new_from_content
{
33 my ($class, $xml) = @_;
34 my ($version, @urls) = @_;
36 my $self = XML
::Rules
->parse(
38 _default
=> 'content',
40 url
=> 'content array',
41 'other-versions' => undef,
55 my @urls = $self->urls;
59 sub _unpack_tar_to_dir
{
60 my ($file, $dir) = @_;
61 my $tar = which
'tar' or which
'gtar';
62 if ($tar && !$ENV{ZEAL_USE_INTERNAL_TAR
}) {
64 $arg = '-xzf' if $file =~ /[.]t?gz$/;
65 $arg = '-xjf' if $file =~ /[.]bz2$/;
66 system $tar, -C
=> $dir, $arg => $file
68 $file = rel2abs
$file;
71 Archive
::Tar
->extract_archive($file);
77 my ($self, $path) = @_;
78 my ($name) = $self->url =~ /([^\/])+$/;
79 my $file = catfile
$path, $name;
80 HTTP
::Tiny
->new->mirror($self->url, $file);
81 _unpack_tar_to_dir
$file, $path;
92 Zeal::Feed - Class representing a Dash/Zeal documentation feed
97 my $feed = Zeal::Feed->new('http://example.com/feed.xml');
98 say $feed->version; # 12.2.3
99 say $feed->url; # http://another.example.com/file.tar.gz
101 # Download to /home/mgv/docsets/file.docset
102 $feed->download('/home/mgv/docsets/');
106 Dash is an offline API documentation browser. Zeal::Feed is a class
107 representing a Dash/Zeal documentation feed.
109 A documentation feed is an XML file describing a docset. It contains
110 the version of the docset and one or more URLs to a (typically
111 .tar.gz) archive of the docset.
117 =item Zeal::Feed->B<new>(I<$url>)
119 Create a Zeal::Feed object from an HTTP URL.
121 =item Zeal::Feed->B<new_from_file>(I<$file>)
123 Create a Zeal::Feed object from a file.
125 =item Zeal::Feed->B<new_from_content>(I<$xml>)
127 Create a Zeal::Feed object from a string.
129 =item $feed->B<version>
131 The version of this feed.
135 A list of URLs to this docset.
139 An URL to this docset, randomly chosen from the list returned by B<urls>.
141 =item $feed->B<download>(I<$path>)
143 Download and unpack the docset inside the I<$path> directory.
145 Uses the F<tar> binary for unpacking if availablem, L<Archive::Tar>
146 otherwise. You can set the ZEAL_USE_INTERNAL_TAR environment variable
147 to a true value to force the use of L<Archive::Tar>.
155 =item ZEAL_USE_INTERNAL_TAR
157 If true, B<download> will always use L<Archive::Tar>.
163 L<Zeal>, L<http://kapeli.com/dash>, L<http://zealdocs.org>
167 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
169 =head1 COPYRIGHT AND LICENSE
171 Copyright (C) 2014-2015 by Marius Gavrilescu
173 This library is free software; you can redistribute it and/or modify
174 it under the same terms as Perl itself, either Perl version 5.20.1 or,
175 at your option, any later version of Perl 5 you may have available.
This page took 0.059001 seconds and 3 git commands to generate.