Skip to content

Commit

Permalink
Added 'metacpan_url' for MetaCPAN links of objects.
Browse files Browse the repository at this point in the history
Supports: Module, Release, Distribution, File & Author.
  • Loading branch information
mickeyn committed Mar 22, 2017
1 parent 1ad2930 commit d3297e6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/metacpan_url.pl
@@ -0,0 +1,24 @@
use strict;
use warnings;
use MetaCPAN::Client;

my $mcpan = MetaCPAN::Client->new();

my $auth = $mcpan->author('HAARG');
my $mod = $mcpan->module('Moo');
my $file = $mcpan->file('HAARG/Moo-2.003001/lib/Moo.pm');
my $dist = $mcpan->distribution('Moo');
my $rel = $mcpan->release({
all => [
{ distribution => 'Moo' },
{ version => '2.002005' },
]
});

printf "AUTHOR : %s\n", $auth->metacpan_url;
printf "RELEASE : %s\n", $rel->next->metacpan_url;
printf "MODULE : %s\n", $mod->metacpan_url;
printf "FILE : %s\n", $file->metacpan_url;
printf "DISTRIBUTION : %s\n", $dist->metacpan_url;

1;
6 changes: 6 additions & 0 deletions lib/MetaCPAN/Client/Author.pm
Expand Up @@ -66,6 +66,8 @@ sub releases {

sub dir { $_[0]->links->{cpan_directory} }

sub metacpan_url { "https://metacpan.org/author/" . $_[0]->pauseid }

1;

__END__
Expand Down Expand Up @@ -255,3 +257,7 @@ by author.
This method returns a L<MetaCPAN::Client::ResultSet> of
L<MetaCPAN::Client::Release> objects. It includes all of the author's releases
with the C<latest> status.
=head2 metacpan_url
Returns a link to the author's page on MetaCPAN.
6 changes: 6 additions & 0 deletions lib/MetaCPAN/Client/Distribution.pm
Expand Up @@ -42,6 +42,8 @@ sub _known_fields { return \%known_fields }
sub rt { $_[0]->bugs->{rt} || {} }
sub github { $_[0]->bugs->{github} || {} }

sub metacpan_url { "https://metacpan.org/release/" . $_[0]->name }

1;

__END__
Expand Down Expand Up @@ -103,3 +105,7 @@ hashref.
Returns the hashref of data for the github bug tracker. This defaults to an
empty hashref.
=head2 metacpan_url
Returns a link to the distribution page on MetaCPAN.
10 changes: 10 additions & 0 deletions lib/MetaCPAN/Client/File.pm
Expand Up @@ -90,6 +90,12 @@ sub source {
);
}

sub metacpan_url {
my $self = shift;
sprintf("https://metacpan.org/source/%s/%s/%s",
$self->author, $self->release, $self->path );
}

1;

__END__
Expand Down Expand Up @@ -279,3 +285,7 @@ Supported types: B<plain>, B<html>, B<x-pod>, B<x-markdown>.
my $source = $module->source();
Returns the source code for the file.
=head2 metacpan_url
Returns a link to the file source page on MetaCPAN.
12 changes: 12 additions & 0 deletions lib/MetaCPAN/Client/Module.pm
Expand Up @@ -6,6 +6,12 @@ package MetaCPAN::Client::Module;
use Moo;
extends 'MetaCPAN::Client::File';

sub metacpan_url {
my $self = shift;
sprintf("https://metacpan.org/pod/release/%s/%s/%s",
$self->author, $self->release, $self->path );
}

1;

__END__
Expand All @@ -23,3 +29,9 @@ This is currently the exact same as L<MetaCPAN::Client::File>.
=head1 ATTRIBUTES
Whatever L<MetaCPAN::Client::File> has.
=head1 METHODS
=head2 metacpan_url
Returns a link to the module page on MetaCPAN.
11 changes: 11 additions & 0 deletions lib/MetaCPAN/Client/Release.pm
Expand Up @@ -55,6 +55,11 @@ foreach my $field (@known_fields) {

sub _known_fields { return \%known_fields }

sub metacpan_url {
my $self = shift;
sprintf( "https://metacpan.org/release/%s/%s", $self->author, $self->name )
}

1;

__END__
Expand Down Expand Up @@ -199,3 +204,9 @@ The file's size in bytes.
Returns a hashref of information about CPAN testers results for this
release. The keys are C<pass>, C<fail>, C<unknown>, and C<na>. The values are
the count of that particular result on CPAN Testers for this release.
=head1 METHODS
=head2 metacpan_url
Returns a link to the release page on MetaCPAN.

0 comments on commit d3297e6

Please sign in to comment.