| 1 | package CPAN::Index::API; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 1 | $CPAN::Index::API::VERSION = '0.007'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Read and write CPAN index files | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Path::Class qw(dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Class::Load qw(load_class); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Moose::Util::TypeConstraints qw(find_type_constraint); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | has files => ( | |||||||||||||||||||||||||||
| 19 | is => 'bare', | ||||||||||||||||||||||||||||
| 20 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 21 | traits => ['Hash'], | ||||||||||||||||||||||||||||
| 22 | handles => { files => 'values', file => 'get', file_names => 'keys' }, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | has repo_path => | |||||||||||||||||||||||||||
| 26 | ( | ||||||||||||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||||||||||
| 28 | isa => 'Str', | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | has repo_uri => | |||||||||||||||||||||||||||
| 32 | ( | ||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||
| 34 | isa => 'Str', | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub BUILDARGS { | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | croak "Please specifiy which files to load" unless $args{files}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | my $constraint = find_type_constraint('ArrayRef[Str]'); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( $constraint->check($args{files}) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | 0 | my %files; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | foreach my $file ( @{ $args{files} } ) | |||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 0 | my $package_name = "CPAN::Index::API::File::$file"; | |||||||||||||||||||||||||||
| 51 | 0 | load_class $package_name; | |||||||||||||||||||||||||||
| 52 | $files{$file} = $package_name->new( | ||||||||||||||||||||||||||||
| 53 | repo_path => $args{repo_path}, | ||||||||||||||||||||||||||||
| 54 | repo_uri => $args{repo_uri}, | ||||||||||||||||||||||||||||
| 55 | 0 | ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $args{files} = \%files; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( $args{repo_path} and not $args{repo_uri} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"repo_path"} and not $args{"repo_uri"}
MC/DC0%0/2
$args{"repo_path"} and not $args{"repo_uri"}
$args{"repo_path"}
not $args{"repo_uri"}
Truth table0%0/3
A and not(B)
A= $args{"repo_path"}B= not $args{"repo_uri"}
| |||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | $args{repo_uri} = URI::file->new( | ||||||||||||||||||||||||||||
| 64 | 0 | dir($args{repo_path})->absolute | |||||||||||||||||||||||||||
| 65 | )->as_string; | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | return \%args; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub new_from_repo_path | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new_from_repo_path: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ( $args{repo_path} and not $args{repo_uri} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"repo_path"} and not $args{"repo_uri"}
MC/DC0%0/2
$args{"repo_path"} and not $args{"repo_uri"}
$args{"repo_path"}
not $args{"repo_uri"}
Truth table0%0/3
A and not(B)
A= $args{"repo_path"}B= not $args{"repo_uri"}
| |||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | $args{repo_uri} = URI::file->new( | ||||||||||||||||||||||||||||
| 78 | 0 | dir($args{repo_path})->absolute | |||||||||||||||||||||||||||
| 79 | )->as_string; | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my $files = delete $args{files}; | |||||||||||||||||||||||||||
| 83 | 0 | my %files; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | croak "Please specifiy which files to load" unless $files; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | foreach my $file ( @$files ) | |||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 0 | my $package_name = "CPAN::Index::API::File::$file"; | |||||||||||||||||||||||||||
| 90 | 0 | load_class $package_name; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | $files{$file} = $package_name->read_from_repo_path( | ||||||||||||||||||||||||||||
| 93 | $args{repo_path} | ||||||||||||||||||||||||||||
| 94 | 0 | ); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | return $class->new( %args, files => \%files ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | sub new_from_repo_uri | ||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new_from_repo_uri: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | my $files = delete $args{files}; | |||||||||||||||||||||||||||
| 105 | 0 | my %files; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | croak "Please specifiy which files to load" unless $files; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | foreach my $file ( @$files ) | |||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 0 | my $package_name = "CPAN::Index::API::File::$file"; | |||||||||||||||||||||||||||
| 112 | 0 | load_class $package_name; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | $files{$file} = $package_name->read_from_repo_uri( | ||||||||||||||||||||||||||||
| 115 | $args{repo_uri} | ||||||||||||||||||||||||||||
| 116 | 0 | ); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | return $class->new( %args, files => \%files ); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub write_all_files | ||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
write_all_files: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 0 | $_->write_to_default_location for $self->files; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub clone { | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | my %new_files; | |||||||||||||||||||||||||||
| 132 | 0 | foreach my $file_name ( $self->file_names ) | |||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||
| 134 | 0 | my $new_file = $self->file($file_name)->clone(%args); | |||||||||||||||||||||||||||
| 135 | 0 | $new_files{$file_name} = $new_file; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | return (blessed $self)->meta->clone_object( | |||||||||||||||||||||||||||
| 139 | $self, files => \%new_files, %args | ||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||
| 147 | =pod | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head1 NAME | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | CPAN::Index::API - Read and write CPAN index files | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 VERSION | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | version 0.007 | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | my $index = CPAN::Index::API->new_from_repo_uri( | ||||||||||||||||||||||||||||
| 160 | repo_uri => 'http://cpan.perl.org/', | ||||||||||||||||||||||||||||
| 161 | files => [qw(PackagesDetails ModList MailRc)], | ||||||||||||||||||||||||||||
| 162 | ); | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | my $packages = $index->file('PackagesDetails'); | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head1 DESRIPTION | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | C<CPAN::Index::API> is a library to read and write CPAN index files. See the | ||||||||||||||||||||||||||||
| 169 | modules in the C<CPAN::Index::API::File> namesace for documentation on the | ||||||||||||||||||||||||||||
| 170 | individual files supported. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | This class provides a convenient interface for working with multiple files | ||||||||||||||||||||||||||||
| 173 | from the same location at the same time. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head1 CONSTRUCTION | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =head2 new | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | Creates a new index object. Accepts the following parameters: | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =over | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =item files | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | Required. Hashrefs whose values are C<CPAN::Index::API::File> objects. The | ||||||||||||||||||||||||||||
| 186 | individual objects can later be accessed by their respective hash key via the | ||||||||||||||||||||||||||||
| 187 | L</file> method. | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =item repo_path | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | Optional. Path to the root of the repository to which the index files belong. | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =item repo_uri | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | Optional. Base uri of the repository to which the index files belong. | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =back | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head2 new_from_repo_path | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | Creates a new index object by reading one or more index files from a local | ||||||||||||||||||||||||||||
| 202 | repository. Accepts the following parameters: | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =over | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =item files | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Required. Arrayref of names of index files to be read. Each name must be the | ||||||||||||||||||||||||||||
| 209 | name of a plugin under the C<CPAN::Index::API::File::> namespace, e.g. | ||||||||||||||||||||||||||||
| 210 | C<PackagesDetails>, C<ModList>, etc. | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =item repo_path | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | Required. Path to the root of the local repository. | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | =back | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =head2 new_from_repo_uri | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | Creates a new index object by reading one or more index files from a remote | ||||||||||||||||||||||||||||
| 221 | repository. Accepts the following parameters: | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =over | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =item files | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | Required. Arrayref of names of index files to be read. Each name must be the | ||||||||||||||||||||||||||||
| 228 | name of a plugin under the C<CPAN::Index::API::File::> namespace, e.g. | ||||||||||||||||||||||||||||
| 229 | C<PackagesDetails>, C<ModList>, etc. | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =item repo_uri | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | Required. Path to the base uri of the remote repository. | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | =back | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | =head1 METHODS | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | =head2 file | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | Given the name of a file plugin loaded within the index, returns the object | ||||||||||||||||||||||||||||
| 242 | corresponding to this index file. | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =head2 repo_path | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | Returns the path to the repository. | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | =head2 repo_uri | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | Returns the base uri of the repository. | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =head2 write_all_files | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | Writes all index files to their default locations under C<repo_path>. | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =head2 clone | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | Creates a new instance of this object, overloading any of the existing | ||||||||||||||||||||||||||||
| 259 | attributes with any arguments passed. | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | Peter Shangov <pshangov@yahoo.com> | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | This software is copyright (c) 2012 by Venda, Inc.. | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 270 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =cut | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||