| 1 | package Net::FTP::Path::Iter; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Iterative, recursive, FTP file finder | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 2 | our $VERSION = '0.07'; | |||||||||
| 12 | |||||||||||
| 13 | 2 | ▶ | use Net::FTP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use File::Spec::Functions qw[ splitpath ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | use parent 'Path::Iterator::Rule'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 2 | ▶ | use Net::FTP::Path::Iter::Dir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 2 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=7 SCAR=20.7
Pod
documented
| |||||||||||
| 46 | |||||||||||
| 47 | 1 | my $class = shift; | |||||||||
| 48 | |||||||||||
| 49 | 1 | my %attr; | |||||||||
| 50 | 1 | ▶ | if ( @_ % 2 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 1 | my $host = shift; | |||||||||
| 52 | 1 | %attr = @_; | |||||||||
| 53 | 1 | $attr{Host} = $host; | |||||||||
| 54 | } | ||||||||||
| 55 | else { | ||||||||||
| 56 | 0 | %attr = @_; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 1 | my $self = $class->SUPER::new(); | |||||||||
| 60 | |||||||||||
| 61 | defined( my $host = delete $attr{Host} ) | ||||||||||
| 62 | 1 | ▶ | or croak( "missing Host attribute\n" ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | |||||||||||
| 64 | defined( my $user = delete $attr{user} ) | ||||||||||
| 65 | 1 | ▶ | or croak( "missing user attribute\n" ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | |||||||||||
| 67 | defined( my $password = delete $attr{password} ) | ||||||||||
| 68 | 1 | ▶ | or croak( "missing password attribute\n" ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | |||||||||||
| 70 | 1 | ▶ | $self->{server} = Net::FTP->new( $host, %attr ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | or croak( "unable to connect to server $host\n" ); | ||||||||||
| 72 | |||||||||||
| 73 | 1 | ▶ | $self->{server}->login( $user, $password ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | or croak( "unable to log in to $host\n" ); | ||||||||||
| 75 | |||||||||||
| 76 | 1 | return $self; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 1 | ▶ | sub _defaults { | ||||||||
|
Subroutine
_defaults: called CC=1 SCAR=1.2
| |||||||||||
| 80 | return ( | ||||||||||
| 81 | _stringify => 0, | ||||||||||
| 82 | follow_symlinks => 1, | ||||||||||
| 83 | depthfirst => 0, | ||||||||||
| 84 | sorted => 1, | ||||||||||
| 85 | loop_safe => 1, | ||||||||||
| 86 | 0 | ▶ | error_handler => sub { die sprintf( '%s: %s', @_ ) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 87 | 1 | visitor => undef, | |||||||||
| 88 | ); | ||||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | sub _fast_defaults { | ||||||||
|
Subroutine
_fast_defaults: not called CC=1 SCAR=6.9
| |||||||||||
| 92 | |||||||||||
| 93 | return ( | ||||||||||
| 94 | 0 | _stringify => 0, | |||||||||
| 95 | follow_symlinks => 1, | ||||||||||
| 96 | depthfirst => -1, | ||||||||||
| 97 | sorted => 0, | ||||||||||
| 98 | loop_safe => 0, | ||||||||||
| 99 | error_handler => undef, | ||||||||||
| 100 | visitor => undef, | ||||||||||
| 101 | ); | ||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 1 | ▶ | sub _objectify { | ||||||||
|
Subroutine
_objectify: called CC=1 SCAR=0.0
| |||||||||||
| 105 | |||||||||||
| 106 | 1 | my ( $self, $path ) = @_; | |||||||||
| 107 | |||||||||||
| 108 | 1 | my ( undef, $directories, $name ) = splitpath( $path ); | |||||||||
| 109 | |||||||||||
| 110 | 1 | $directories =~ s{(.+)/$}{$1}; | |||||||||
| 111 | |||||||||||
| 112 | 1 | my %attr = ( | |||||||||
| 113 | parent => $directories, | ||||||||||
| 114 | name => $name, | ||||||||||
| 115 | path => $path, | ||||||||||
| 116 | ); | ||||||||||
| 117 | |||||||||||
| 118 | 1 | return Net::FTP::Path::Iter::Dir->new( server => $self->{server}, %attr ); | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 5 | ▶ | sub _children { | ||||||||
|
Subroutine
_children: called CC=1 SCAR=0.0
| |||||||||||
| 122 | |||||||||||
| 123 | 5 | my ( undef, $path ) = @_; | |||||||||
| 124 | |||||||||||
| 125 | 5 | return map { [ $_->{name}, $_ ] } $path->_children; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 1 | ▶ | sub _iter { | ||||||||
|
Subroutine
_iter: called CC=1 SCAR=0.0
| |||||||||||
| 129 | |||||||||||
| 130 | 1 | my $self = shift; | |||||||||
| 131 | 1 | my $defaults = shift; | |||||||||
| 132 | |||||||||||
| 133 | 1 | $defaults->{loop_safe} = 0; | |||||||||
| 134 | |||||||||||
| 135 | 1 | $self->SUPER::_iter( $defaults, @_ ); | |||||||||
| 136 | |||||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | 2 | 1; | |||||||||
| 140 | |||||||||||
| 141 | # | ||||||||||
| 142 | # This file is part of Net-FTP-Path-Iter | ||||||||||
| 143 | # | ||||||||||
| 144 | # This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory. | ||||||||||
| 145 | # | ||||||||||
| 146 | # This is free software, licensed under: | ||||||||||
| 147 | # | ||||||||||
| 148 | # The GNU General Public License, Version 3, June 2007 | ||||||||||
| 149 | # | ||||||||||
| 150 | |||||||||||
| 151 | __END__ | ||||||||||