Commit | Line | Data |
b67ffc2e |
1 | package BackPAN::Index::File; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use File::Basename qw(basename); |
7 | |
8 | use overload |
9 | q[""] => sub { $_[0]->path }, |
10 | fallback => 1; |
11 | |
12 | use BackPAN::Index::Role::AsHash; |
13 | |
14 | sub data_methods { |
15 | return qw(path date size); |
16 | } |
17 | |
18 | sub url { |
19 | my $self = shift; |
20 | return "http://backpan.cpan.org/" . $self->path; |
21 | } |
22 | |
23 | sub filename { |
24 | my $self = shift; |
25 | return basename $self->path; |
26 | } |
27 | |
28 | # Backwards compatibility with PBP |
29 | sub prefix { |
30 | my $self = shift; |
31 | return $self->path; |
32 | } |
33 | |
34 | sub release { |
35 | my $self = shift; |
36 | |
37 | my $schema = $self->result_source->schema; |
38 | my($release) = $schema->resultset("Release") |
39 | ->search({ file => $self->path }, { rows => 1 }) |
40 | ->first; |
41 | |
42 | return $release; |
43 | } |
44 | |
45 | 1; |
46 | |
47 | __END__ |
48 | |
49 | =head1 NAME |
50 | |
51 | BackPAN::Index::File - Represent a file on BackPAN |
52 | |
53 | =head1 SYNOPSIS |
54 | |
55 | my $b = BackPAN::Index->new(); |
56 | my $file = $b->file("authors/id/L/LB/LBROCARD/Acme-Colour-0.16.tar.gz"); |
57 | print " Date: " . $file->date . "\n"; |
58 | print " Path: " . $file->path . "\n"; |
59 | print " Size: " . $file->size . "\n"; |
60 | print " URL: " . $file->url . "\n"; |
61 | |
62 | =head1 DESCRIPTION |
63 | |
64 | BackPAN::Index::File objects represent files on BackPAN. It may |
65 | represent a release, a readme or meta file or just some random stuff |
66 | on BackPAN. |
67 | |
68 | =head1 METHODS |
69 | |
70 | =head2 date |
71 | |
72 | my $date = $file->date; |
73 | |
74 | Returns the upload date of the file, in UNIX epoch seconds. |
75 | |
76 | =head2 path |
77 | |
78 | my $path = $file->path; |
79 | |
80 | Returns the full path to the file on CPAN. |
81 | |
82 | =head2 size |
83 | |
84 | my $size = $file->size; |
85 | |
86 | Returns the size of the file in bytes. |
87 | |
88 | =head2 url |
89 | |
90 | my $url = $file->url; |
91 | |
92 | Returns a URL to the file on a BackPAN mirror. |
93 | |
94 | =head2 filename |
95 | |
96 | my $filename = $file->filename; |
97 | |
98 | Returns the filename part of the path. |
99 | |
100 | =head2 release |
101 | |
102 | my $release = $file->release; |
103 | |
104 | Returns the release associated with this file, if any, as a |
105 | L<BackPAN::Index::Release> instance. |
106 | |
107 | =head2 as_hash |
108 | |
109 | my $data = $file->as_hash; |
110 | |
111 | Returns a hash ref containing the data inside C<$file>. |
112 | |
113 | |
114 | =head1 AUTHOR |
115 | |
116 | Leon Brocard <acme@astray.com> |
117 | |
118 | =head1 COPYRIGHT |
119 | |
120 | Copyright (C) 2005-2009, Leon Brocard |
121 | |
122 | This module is free software; you can redistribute it or modify it under |
123 | the same terms as Perl itself. |
124 | |
125 | =head1 SEE ALSO |
126 | |
127 | L<BackPAN::Index>, L<BackPAN::Index::Release> |