BackPAN-Index

 view release on metacpan or  search on metacpan

lib/BackPAN/Index/File.pm  view on Meta::CPAN

use utf8;
package BackPAN::Index::File;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

use strict;
use warnings;

use base 'DBIx::Class::Core';
__PACKAGE__->table("files");
__PACKAGE__->add_columns(
  "path",
  { data_type => "text", is_nullable => 0 },
  "date",
  { data_type => "integer", is_nullable => 0 },
  "size",
  { data_type => "integer", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("path");
__PACKAGE__->might_have(
  "release",
  "BackPAN::Index::Release",
  { "foreign.path" => "self.path" },
  { cascade_copy => 0, cascade_delete => 0 },
);


# Created by DBIx::Class::Schema::Loader v0.07033 @ 2012-12-27 01:39:08
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:gqi9QR+IxPMmdduz2/1BHA

use Mouse;
with 'BackPAN::Index::Role::AsHash';

use URI;
use File::Basename qw(basename);

use overload
  q[""]         => sub { $_[0]->path },
  fallback      => 1;

sub backpan_root {
    return URI->new("http://backpan.perl.org/");
}

sub data_methods {
    return qw(path date size);
}

sub url {
    my $self = shift;
    my $url = $self->backpan_root;
    $url->path($self->path);
    return $url;
}

sub filename {
    my $self = shift;
    return basename $self->path;
}

# Backwards compatibility with PBP
sub prefix {
    my $self = shift;
    return $self->path;
}

sub release {
    my $self = shift;

    my $schema = $self->result_source->schema;
    my($release) = $schema->resultset("Release")
                          ->search({ file => $self->path }, { rows => 1 })
                          ->first;

    return $release;
}

1;

__END__

=head1 NAME

BackPAN::Index::File - Represent a file on BackPAN



( run in 0.720 second using v1.01-cache-2.11-cpan-39bf76dae61 )