NAME

Test::VirtualModule

DESCRIPTION

This package allows you to generate perl modules on flight for unit-testing. This package is usable when you have complex environment with some tricky perl modules inside of it, which can't be installed without full environment. And you unable to write unit tests.

This module allows you to cheat and tell to perl that these modules already loaded.

SYNOPSIS

# load virtual module
use Test::VirtualModule qw/BlahBlahBlah::FooBar/;
# import mocked module, it's ok
use BlahBlahBlah::FooBar;
# Mock constructor
Test::VirtualModule->mock_sub('BlahBlahBlah::FooBar',
    new => sub {
        my $self = {};
        bless $self, 'BlahBlahBlah::FooBar';
        return $self;
    }
);
# create object
my $object = BlahBlahBlah::FooBar->new();

That's all.

mock_sub

Alows you to mock subroutines of specified module.

Test::VirtualModule->mock_sub(
    'SomeModule',
    get_property    =>  sub {
        return 1;
    },
);
SomeModule->get_property(1);