]>
iEval git - zeal.git/blob - lib/Zeal/Feed.pm
8 our $VERSION = '0.001001';
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 $file = rel2abs
$file;
64 my $tar = which
'tar' or which
'gtar';
66 # uncoverable branch true
67 # uncoverable condition false
68 local $ENV{ZEAL_USE_INTERNAL_TAR
} = 1 if $file =~ /gz$|bz2$/ && $^O
eq 'solaris';
70 if ($tar && !$ENV{ZEAL_USE_INTERNAL_TAR
}) {
72 $arg = '-xzf' if $file =~ /[.]t?gz$/;
73 $arg = '-xjf' if $file =~ /[.]bz2$/;
74 system $tar, $arg => $file
76 Archive
::Tar
->extract_archive($file);
82 my ($self, $path) = @_;
83 my ($name) = $self->url =~ /([^\/])+$/;
84 my $file = catfile
$path, $name;
85 HTTP
::Tiny
->new->mirror($self->url, $file);
86 _unpack_tar_to_dir
$file, $path;
97 Zeal::Feed - Class representing a Dash/Zeal documentation feed
102 my $feed = Zeal::Feed->new('http://example.com/feed.xml');
103 say $feed->version; # 12.2.3
104 say $feed->url; # http://another.example.com/file.tar.gz
106 # Download to /home/mgv/docsets/file.docset
107 $feed->download('/home/mgv/docsets/');
111 Dash is an offline API documentation browser. Zeal::Feed is a class
112 representing a Dash/Zeal documentation feed.
114 A documentation feed is an XML file describing a docset. It contains
115 the version of the docset and one or more URLs to a (typically
116 .tar.gz) archive of the docset.
122 =item Zeal::Feed->B<new>(I<$url>)
124 Create a Zeal::Feed object from an HTTP URL.
126 =item Zeal::Feed->B<new_from_file>(I<$file>)
128 Create a Zeal::Feed object from a file.
130 =item Zeal::Feed->B<new_from_content>(I<$xml>)
132 Create a Zeal::Feed object from a string.
134 =item $feed->B<version>
136 The version of this feed.
140 A list of URLs to this docset.
144 An URL to this docset, randomly chosen from the list returned by B<urls>.
146 =item $feed->B<download>(I<$path>)
148 Download and unpack the docset inside the I<$path> directory.
150 Uses the F<tar> binary for unpacking if availablem, L<Archive::Tar>
151 otherwise. You can set the ZEAL_USE_INTERNAL_TAR environment variable
152 to a true value to force the use of L<Archive::Tar>.
160 =item ZEAL_USE_INTERNAL_TAR
162 If true, B<download> will always use L<Archive::Tar>.
168 L<Zeal>, L<http://kapeli.com/dash>, L<http://zealdocs.org>
172 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
174 =head1 COPYRIGHT AND LICENSE
176 Copyright (C) 2014-2015 by Marius Gavrilescu
178 This library is free software; you can redistribute it and/or modify
179 it under the same terms as Perl itself, either Perl version 5.20.1 or,
180 at your option, any later version of Perl 5 you may have available.
This page took 0.063748 seconds and 5 git commands to generate.