Baseline - Launch of backpan.org
[catagits/BackPAN-Web.git] / lib / BackPAN / Index / File.pm
CommitLineData
b67ffc2e 1package BackPAN::Index::File;
2
3use strict;
4use warnings;
5
6use File::Basename qw(basename);
7
8use overload
9 q[""] => sub { $_[0]->path },
10 fallback => 1;
11
12use BackPAN::Index::Role::AsHash;
13
14sub data_methods {
15 return qw(path date size);
16}
17
18sub url {
19 my $self = shift;
20 return "http://backpan.cpan.org/" . $self->path;
21}
22
23sub filename {
24 my $self = shift;
25 return basename $self->path;
26}
27
28# Backwards compatibility with PBP
29sub prefix {
30 my $self = shift;
31 return $self->path;
32}
33
34sub 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
451;
46
47__END__
48
49=head1 NAME
50
51BackPAN::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
64BackPAN::Index::File objects represent files on BackPAN. It may
65represent a release, a readme or meta file or just some random stuff
66on BackPAN.
67
68=head1 METHODS
69
70=head2 date
71
72 my $date = $file->date;
73
74Returns the upload date of the file, in UNIX epoch seconds.
75
76=head2 path
77
78 my $path = $file->path;
79
80Returns the full path to the file on CPAN.
81
82=head2 size
83
84 my $size = $file->size;
85
86Returns the size of the file in bytes.
87
88=head2 url
89
90 my $url = $file->url;
91
92Returns a URL to the file on a BackPAN mirror.
93
94=head2 filename
95
96 my $filename = $file->filename;
97
98Returns the filename part of the path.
99
100=head2 release
101
102 my $release = $file->release;
103
104Returns the release associated with this file, if any, as a
105L<BackPAN::Index::Release> instance.
106
107=head2 as_hash
108
109 my $data = $file->as_hash;
110
111Returns a hash ref containing the data inside C<$file>.
112
113
114=head1 AUTHOR
115
116Leon Brocard <acme@astray.com>
117
118=head1 COPYRIGHT
119
120Copyright (C) 2005-2009, Leon Brocard
121
122This module is free software; you can redistribute it or modify it under
123the same terms as Perl itself.
124
125=head1 SEE ALSO
126
127L<BackPAN::Index>, L<BackPAN::Index::Release>