File Coverage

blib/lib/Metabase/Resource/perl/commit.pm
Criterion Covered Total %
statement 26 26 100.0
branch 2 4 50.0
condition 3 5 60.0
subroutine 9 9 100.0
pod 2 2 100.0
total 42 46 91.3


line stmt bran cond sub pod time code
1 1     1   13 use 5.006;
  1         2  
2 1     1   2 use strict;
  1         1  
  1         15  
3 1     1   2 use warnings;
  1         1  
  1         37  
4              
5             package Metabase::Resource::perl::commit;
6              
7             our $VERSION = '0.025';
8              
9 1     1   3 use Carp ();
  1         1  
  1         13  
10              
11 1     1   3 use Metabase::Resource::perl;
  1         1  
  1         217  
12             our @ISA = qw/Metabase::Resource::perl/;
13              
14             sub _metadata_types {
15 1     1   13 return { sha1 => '//str', };
16             }
17              
18             sub _init {
19 1     1   1 my ($self) = @_;
20              
21 1         32 my ($string) = $self =~ m{\Aperl:///commit/(.+)\z};
22 1 50 33     7 Carp::confess("could not determine commit from '$self'\n")
23             unless defined $string && length $string;
24              
25 1         6 my $sha1 = $1;
26 1 50       6 Carp::confess("illegal commit hash")
27             unless $sha1 =~ m/^[a-f0-9]+$/;
28              
29 1         8 $self->_add( 'sha1' => $sha1 );
30              
31 1         2 return $self;
32             }
33              
34             #pod =method full_url
35             #pod
36             #pod my $url = $self->full_url($host);
37             #pod
38             #pod Returns an ordinary HTTP URL to the resource. If C<$host> is not
39             #pod given, it defaults to the official master Perl repository at
40             #pod L.
41             #pod
42             #pod =cut
43              
44             sub full_url {
45 2     2 1 14 my ( $self, $host ) = @_;
46 2   100     8 $host ||= 'perl5.git.perl.org';
47 2         6 return "http://${host}/perl.git/" . $self->sha1;
48             }
49              
50             # 'commit' validates during _init, really
51 1     1 1 2 sub validate { 1 }
52              
53             #pod =pod
54             #pod
55             #pod =head1 SYNOPSIS
56             #pod
57             #pod my $resource = Metabase::Resource->new(
58             #pod 'perl:///commit/8c576062',
59             #pod );
60             #pod
61             #pod my $resource_meta = $resource->metadata;
62             #pod my $typemap = $resource->metadata_types;
63             #pod my $url = $self->full_url;
64             #pod
65             #pod =head1 DESCRIPTION
66             #pod
67             #pod Generates resource metadata for resources of the scheme 'perl:///commit'.
68             #pod
69             #pod my $resource = Metabase::Resource->new(
70             #pod 'perl:///commit/8c576062',
71             #pod );
72             #pod
73             #pod For the example above, the resource metadata structure would contain the
74             #pod following elements:
75             #pod
76             #pod scheme => perl
77             #pod type => commit
78             #pod sha1 => 8c576062
79             #pod
80             #pod =head1 BUGS
81             #pod
82             #pod Please report any bugs or feature using the CPAN Request Tracker.
83             #pod Bugs can be submitted through the web interface at
84             #pod L
85             #pod
86             #pod When submitting a bug or request, please include a test-file or a patch to an
87             #pod existing test-file that illustrates the bug or desired feature.
88             #pod
89             #pod =cut
90              
91             1;
92              
93             # ABSTRACT: class for Metabase resources about perl commits
94              
95             __END__