Skip to content

Commit

Permalink
Update for renamed htmldoc URI template.
Browse files Browse the repository at this point in the history
The old name was `doc`. The variable has also been changed from `doc` to
`docpath`. This is consistent with the changes in PGXN::API v0.12.0.
  • Loading branch information
theory committed Apr 20, 2011
1 parent 01bd473 commit a625a46
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 68 deletions.
40 changes: 20 additions & 20 deletions lib/WWW/PGXN.pm
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,21 @@ BEGIN {
}
}

sub doc_path_for {
my ($self, $dist, $version, $doc) = @_;
sub html_doc_path_for {
my ($self, $dist, $version, $path) = @_;
# XXX Nasty hack until we get + operator in URI Template v4.
local $URI::Escape::escapes{'/'} = '/';
$self->_path_for(doc => {
dist => $dist,
version => $version,
doc => $doc,
'+doc' => $doc,
$self->_path_for(htmldoc => {
dist => $dist,
version => $version,
docpath => $path,
'+docpath' => $path,
});
}

sub doc_url_for {
sub html_doc_url_for {
my $self = shift;
return URI->new($self->url . $self->doc_path_for(@_));
return URI->new($self->url . $self->html_doc_path_for(@_));
}

sub _uri_templates {
Expand Down Expand Up @@ -443,7 +443,7 @@ argument. Pass C<txt> to be specific about wanting the text document.
=head3 C<search>
my $results = $pgxn->search( query => 'tap' );
$results = $pgxn->search( query => 'wicked', index => 'dist' );
$results = $pgxn->search( query => 'wicked', index => 'dists' );
Sends a search query to the API server (not supported for mirrors). For an API
server accessed via a C<file:> URL, L<PGXN::API::Searcher> is required and
Expand All @@ -461,20 +461,20 @@ syntax of the query. Required.
=item index
The name of the search index to query. The default is "doc". The possible
The name of the search index to query. The default is "docs". The possible
values are:
=over
=item doc
=item docs
=item dist
=item dists
=item extension
=item extensions
=item user
=item users
=item tag
=item tags
=back
Expand Down Expand Up @@ -514,9 +514,9 @@ archive file containing the distribution itself.
Returns the URL for a distribution source file. This URL is available only
from an API server, not a mirror.
=head3 C<doc_url_for>
=head3 C<html_doc_url_for>
my $doc_url = $pgxn->doc_url_for($dist_name, $dist_version, $doc_path);
my $doc_url = $pgxn->html_doc_url_for($dist_name, $dist_version, $doc_path);
Returns the URL for a distribution documentation file. This URL is available
only from an API server, not a mirror.
Expand Down Expand Up @@ -561,9 +561,9 @@ Returns the download path for a distribution and version.
Returns the path for a distribution source file. This path is available only
from an API server, not a mirror.
=head3 C<doc_path_for>
=head3 C<html_doc_path_for>
my $doc_path = $pgxn->doc_path_for($dist_name, $dist_version, $doc_path);
my $doc_path = $pgxn->html_doc_path_for($dist_name, $dist_version, $doc_path);
Returns the PATH for a distribution documentation file. This PATH is available
only from an API server, not a mirror.
Expand Down
47 changes: 24 additions & 23 deletions lib/WWW/PGXN/Distribution.pm
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,31 @@ sub source_path {
);
}

sub url_for_doc {
sub url_for_html_doc {
my $self = shift;
my $uri = $self->path_for_doc(shift) or return;
my $uri = $self->path_for_html_doc(shift) or return;
return URI->new($self->{_pgxn}->url . $uri);
}

sub path_for_doc {
sub path_for_html_doc {
my ($self, $path) = @_;
$self->_merge_meta unless $self->{version};
return unless $self->{docs} && $self->{docs}{$path};

my $tmpl = $self->{_pgxn}->_uri_templates->{doc} or return;
my $tmpl = $self->{_pgxn}->_uri_templates->{htmldoc} or return;
# XXX Nasty hack until we get + operator in URI Template v4.
local $URI::Escape::escapes{'/'} = '/';
$tmpl->process(
dist => $self->name,
version => $self->version,
doc => $path,
'+doc' => $path, # XXX Part of above-mentioned hack.
dist => $self->name,
version => $self->version,
docpath => $path,
'+docpath' => $path, # XXX Part of above-mentioned hack.
);
}

sub body_for_doc {
sub body_for_html_doc {
my $self = shift;
my $url = $self->url_for_doc(shift) or return;
my $url = $self->url_for_html_doc(shift) or return;
my $res = $self->{_pgxn}->_fetch($url) or return;
utf8::decode $res->{content};
return $res->{content};
Expand Down Expand Up @@ -340,7 +340,7 @@ keys are paths to documentation files, and the values are hashes with at least
one key, C<title> which contains the title, of course. A second key,
C<abstract>, is optional and contains an abstract of the document. The
documentation files are stored as HTML and may be fetched via
C<body_for_doc()>.
C<body_for_html_doc()>.
=head3 C<no_index>
Expand Down Expand Up @@ -652,29 +652,30 @@ for the given release status. The supported release statuses are:
Returns a list of the versions for a particular release status, if any. The
are returned in order from most to least recent.
=head3 C<url_for_doc>
=head3 C<url_for_html_doc>
# returns http://api.pgxn.org/dist/pair/pair-0.1.1/doc/pair.html
my $doc_url = $distribution->url_for_doc('doc/pair');
my $doc_url = $distribution->url_for_html_doc('doc/pair');
The absolute URL to a documentation file. Pass a document path to get its URL.
The keys in the C<docs> hash reference represent all known document paths. If
connected to a mirror, rather than an API server, C<undef> will be returned.
Otherwise, if not document exists at that path, an exception will be thrown.
The absolute URL to an HTML documentation file. Pass a document path to get
its URL. The keys in the C<docs> hash reference represent all known document
paths. If connected to a mirror, rather than an API server, C<undef> will be
returned. Otherwise, if not document exists at that path, an exception will be
thrown.
=head3 C<path_for_doc>
=head3 C<path_for_html_doc>
# returns /dist/pair/pair-0.1.1/doc/pair.html
my $doc_url = $distribution->path_for_doc('doc/pair');
my $doc_url = $distribution->path_for_html_doc('doc/pair');
The path to a documentation file. Pass a document path to get its URL. The
keys in the C<docs> hash reference represent all known document paths. If
The path to an HTML documentation file. Pass a document path to get its URL.
The keys in the C<docs> hash reference represent all known document paths. If
connected to a mirror, rather than an API server, C<undef> will be returned.
Otherwise, if not document exists at that path, an exception will be thrown.
=head3 C<body_for_doc>
=head3 C<body_for_html_doc>
my $body = $distribution->body_for_doc('README');
my $body = $distribution->body_for_html_doc('README');
Returns the body of an HTML document. Pass in the path to the doc (minus a
suffix) to retrieve its contents. They keys in the hash returned by C<docs>
Expand Down
8 changes: 4 additions & 4 deletions t/base.t
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ is $pgxn->user_url_for('theory'),
'file:t/mirror/user/theory.json',
'user_url_for() should work';

is $pgxn->doc_url_for('pair', '0.1.2', 'doc/foo'),
is $pgxn->html_doc_url_for('pair', '0.1.2', 'doc/foo'),
'file:t/mirror/dist/pair/0.1.2/doc/foo.html',
'doc_url_for() should work';
'html_doc_url_for() should work';

is $pgxn->meta_path_for('pair', '1.2.0'),
'/dist/pair/1.2.0/META.json',
Expand All @@ -139,9 +139,9 @@ is $pgxn->user_path_for('theory'),
'/user/theory.json',
'user_path_for() should work';

is $pgxn->doc_path_for('pair', '0.1.2', 'doc/foo'),
is $pgxn->html_doc_path_for('pair', '0.1.2', 'doc/foo'),
'/dist/pair/0.1.2/doc/foo.html',
'doc_path_for() should work';
'html_doc_path_for() should work';

##############################################################################
# Test spec fetching.
Expand Down
37 changes: 18 additions & 19 deletions t/dist.t
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ can_ok $dist => qw(
source_url
source_path
download_to
body_for_doc
url_for_doc
path_for_doc
body_for_html_doc
url_for_html_doc
path_for_html_doc
);
is $dist->{_pgxn}, $pgxn, 'It should contain the WWW::PGXN object';

Expand Down Expand Up @@ -135,7 +135,7 @@ is_deeply $dist->docs, {
'doc/pair' => { title => 'pair', abstract => 'A key/value pair data type' }
}, 'Should have docs hash';

ok my $doc = $dist->body_for_doc('README'),
ok my $doc = $dist->body_for_html_doc('README'),
'Fetch the README body';

# Contents should be the decoded HTML.
Expand All @@ -147,7 +147,7 @@ is $doc, do {
}, 'Should have the encoded contents of the file';

# Do the same for the doc.
ok $doc = $dist->body_for_doc('doc/pair'),
ok $doc = $dist->body_for_html_doc('doc/pair'),
'Fetch the doc/pair body';
is $doc, do {
my $fn = catfile qw(t mirror dist pair 0.1.1 doc pair.html);
Expand All @@ -156,23 +156,23 @@ is $doc, do {
<$fh>;
}, 'Should have the encoded contents of the doc/pair file';

is $dist->url_for_doc('README'), 'file:t/mirror/dist/pair/0.1.1/README.html',
is $dist->url_for_html_doc('README'), 'file:t/mirror/dist/pair/0.1.1/README.html',
'Should have README URL';
is $dist->url_for_doc('doc/pair'), 'file:t/mirror/dist/pair/0.1.1/doc/pair.html',
is $dist->url_for_html_doc('doc/pair'), 'file:t/mirror/dist/pair/0.1.1/doc/pair.html',
'Should have doc/pair URL';
is $dist->path_for_doc('README'), '/dist/pair/0.1.1/README.html',
is $dist->path_for_html_doc('README'), '/dist/pair/0.1.1/README.html',
'Should have README path';
is $dist->path_for_doc('doc/pair'), '/dist/pair/0.1.1/doc/pair.html',
is $dist->path_for_html_doc('doc/pair'), '/dist/pair/0.1.1/doc/pair.html',
'Should have doc/pair path';
is $dist->path_for_doc('doc/nonexistent'), undef,
is $dist->path_for_html_doc('doc/nonexistent'), undef,
'Should get undef for nonexistent path';

# Make sure we have no errors if there's no doc URI template.
delete $pgxn->_uri_templates->{doc};
is $dist->body_for_doc('README'), undef,
delete $pgxn->_uri_templates->{htmldoc};
is $dist->body_for_html_doc('README'), undef,
'Should get no errors when no doc URI template';
is $dist->url_for_doc('README'), undef, 'Should again have no README URL';
is $dist->path_for_doc('README'), undef,
is $dist->url_for_html_doc('README'), undef, 'Should again have no README URL';
is $dist->path_for_html_doc('README'), undef,
'Should again have no README path';

ok $dist = $pgxn->get_distribution('pair'), 'Find current pair (0.1.2)';
Expand All @@ -185,13 +185,12 @@ is_deeply $dist->docs, {
ok $dist = $pgxn->get_distribution('pair' => '0.1.0'),
'Find pair 0.1.0';
is_deeply $dist->docs, {}, 'Should have no docs';
is $dist->body_for_doc('README'), undef, 'Should have no README.html';
is $dist->body_for_doc('doc/pair'), undef, 'Should have no doc/pair.html';
is $dist->url_for_doc('README'), undef, 'Should have no README URL';
is $dist->path_for_doc('README'), undef,
is $dist->body_for_html_doc('README'), undef, 'Should have no README.html';
is $dist->body_for_html_doc('doc/pair'), undef, 'Should have no doc/pair.html';
is $dist->url_for_html_doc('README'), undef, 'Should have no README URL';
is $dist->path_for_html_doc('README'), undef,
'Should have no README path';


##############################################################################
# Test merging.
ok $dist = $pgxn->get_distribution('pair'),
Expand Down
3 changes: 1 addition & 2 deletions t/mirror/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"mirrors": "/meta/mirrors.json",
"stats": "/stats/{stats}.json",
"source": "/src/{dist}/{dist}-{version}/",
"doc": "/dist/{dist}/{version}/{+doc}.html",
"htmldoc": "/dist/{dist}/{version}/{+docpath}.html",
"spec": "/meta/spec.{format}",
"stats": "/stats/{stats}.json"
}

1 change: 1 addition & 0 deletions t/pod-spelling.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ API
metadata
JSON
CPAN
dists

0 comments on commit a625a46

Please sign in to comment.