File: Item.pm

package info (click to toggle)
libcpanplus-perl 0.9152-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,708 kB
  • ctags: 1,592
  • sloc: perl: 36,423; sh: 30; makefile: 7
file content (52 lines) | stat: -rw-r--r-- 1,156 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package File::Fetch::Item;

use strict;
use base 'File::Fetch';

use Params::Check               qw[check];
use Locale::Maketext::Simple    Style => 'gettext';

$Params::Check::VERBOSE = 1;

### template for new() and autogenerated accessors ###
my $Tmpl = {
    scheme  => { default => 'http' },
    host    => { default => 'localhost' },
    path    => { default => '/' },
    file    => { required => 1 },
    uri     => { required => 1 },
};

for my $method ( keys %$Tmpl ) {
    no strict 'refs';
    *$method = sub {
                    my $self = shift;
                    $self->{$method} = $_[0] if @_;
                    return $self->{$method};
                }
}

sub new {
    my $class = shift;
    my %hash  = @_;

    my $args = check( $Tmpl, \%hash ) or return;

    bless $args, $class;

    if( lc($args->scheme) ne 'file' and not $args->host ) {
        return File::Fetch->_error(loc(
            "Hostname required when fetching from '%1'",$args->scheme));
    }

    for (qw[path file]) {
        unless( $args->$_ ) {
            return File::Fetch->_error(loc("No '%1' specified",$_));
        }
    }

    return $args;
}


1;