File Coverage

blib/lib/BackPAN/Index/File.pm
Criterion Covered Total %
statement 35 35 100.0
branch n/a
condition n/a
subroutine 14 14 100.0
pod 2 5 40.0
total 51 54 94.4


line stmt bran cond sub pod time code
1 13     13   4730860 use utf8;
  13         51  
  13         134  
2             package BackPAN::Index::File;
3              
4             # Created by DBIx::Class::Schema::Loader
5             # DO NOT MODIFY THE FIRST PART OF THIS FILE
6              
7 13     13   642 use strict;
  13         31  
  13         635  
8 13     13   125 use warnings;
  13         25  
  13         639  
9              
10 13     13   79 use base 'DBIx::Class::Core';
  13         24  
  13         3593  
11             __PACKAGE__->table("files");
12             __PACKAGE__->add_columns(
13             "path",
14             { data_type => "text", is_nullable => 0 },
15             "date",
16             { data_type => "integer", is_nullable => 0 },
17             "size",
18             { data_type => "integer", is_nullable => 0 },
19             );
20             __PACKAGE__->set_primary_key("path");
21             __PACKAGE__->might_have(
22             "release",
23             "BackPAN::Index::Release",
24             { "foreign.path" => "self.path" },
25             { cascade_copy => 0, cascade_delete => 0 },
26             );
27              
28              
29             # Created by DBIx::Class::Schema::Loader v0.07033 @ 2012-12-27 01:39:08
30             # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gqi9QR+IxPMmdduz2/1BHA
31              
32 13     13   179688 use Mouse;
  13         34660  
  13         110  
33             with 'BackPAN::Index::Role::AsHash';
34              
35 13     13   196916 use URI;
  13         92810  
  13         457  
36 13     13   227 use File::Basename qw(basename);
  13         30  
  13         1820  
37              
38             use overload
39 7     7   10569 q[""] => sub { $_[0]->path },
40 13     13   87 fallback => 1;
  13         27  
  13         130  
41              
42             sub backpan_root {
43 2     2 0 20 return URI->new("http://backpan.perl.org/");
44             }
45              
46             sub data_methods {
47 1     1 0 5 return qw(path date size);
48             }
49              
50             sub url {
51 2     2 1 6059 my $self = shift;
52 2         14 my $url = $self->backpan_root;
53 2         262 $url->path($self->path);
54 2         210 return $url;
55             }
56              
57             sub filename {
58 3     3 1 30144 my $self = shift;
59 3         137 return basename $self->path;
60             }
61              
62             # Backwards compatibility with PBP
63             sub prefix {
64 1     1 0 3971 my $self = shift;
65 1         46 return $self->path;
66             }
67              
68             sub release {
69             my $self = shift;
70              
71             my $schema = $self->result_source->schema;
72             my($release) = $schema->resultset("Release")
73             ->search({ file => $self->path }, { rows => 1 })
74             ->first;
75              
76             return $release;
77             }
78              
79             1;
80              
81             __END__