++ed by:
Christian Walde

NAME

Net::FTP::Mock - test code using Net::FTP without having an FTP server

VERSION

version 0.103300

SYNOPSIS

    use Net::FTP::Mock (
        localhost => {
            username => { password => {
                active => 1,
                root => "t/remote_ftp/"
            }},
        },
        ftp.work.com => {
            harry => { god => {
                active => 1,
                root => "t/other_remote_ftp/"
            }},
        },
    );

    use Net::FTP; # will do nothing, since Mock already blocked it

    # $ftp here actually is a Net::FTP::Mock object,
    # but when inspected with isa() it happily claims to be Net::FTP
    my $ftp = Net::FTP->new("ftp.work.com", Debug => 0) or die "Cannot connect to some.host.name: $@";

    # all of these do what you'd think they do, only instead of acting
    # on a real ftp server, they act no the data provided via import
    # and the local harddisk
    $ftp->login( "harry",'god' ) or die "Cannot login ", $ftp->message;
    $ftp->get("that.file") or die "get failed ", $ftp->message;
    $ftp->quit;

DESCRIPTION

Net::FTP::Mock is designed to make code using Net::FTP testable without having to set up actual FTP servers. When calling its import(), usually by way of use, you can pass it a hash detailing virtual servers, their accounts, as well as directories that those accounts map to on the local machine.

You can then interact with the Net::FTP::Mock object exactly as you would with a real one.

NOTE: This is a work in progress and much of Net::FTP's functionality is not yet emulated. If it behaves odd, look at the code or yell at me. Contributions on github are very welcome.

NAME

test code using Net::FTP without having an FTP server

METHODS

Net::FTP::new

Factory method that is implanted into Net::FTP's namespace and returns a Net::FTP::Mock object. Should behave exactly like Net::FTP's new() behaves.

servers

Class attribute that stores the servers hashref passed when the module is used.

Net::FTP::Mock->import( %server_details );

Blocks Net::FTP's namespace in %INC and prepares the servers to be emulated.

isa

Overrides isa to ensure that Moose's type checks recognize this as a Net::FTP object.

SUPPORTED NET::FTP METHODS

code

message

binary

get

quit

mdtm

size

login

ACKNOWLEDGEMENTS

Thanks to Tr@ffics and especially Jens Muskewitz for granting permission to release this module.

Many thanks to mst and rjbs who fielded my newbie questions in #moose and helped me figure out how to actually create the Mock object from Net::FTP's mainspace, as well as how to get the Mock object to masquerade as Net::FTP.

CONTRIBUTIONS

Since I'm not sure how much time i can devote to this, I'm happy about any help. The code is up on github and i'll accept any helping pull requests.

AUTHOR

Christian Walde <mithaldu@yahoo.de>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2010 by Christian Walde.

This is free software, licensed under:

  DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 2004



Hosting generously
sponsored by Bytemark