mocked(3pm)
π¦ mocked β NAME π¦
okay so, bestie, mocked is literally just: use mocked libraries in unit tests π
that's the whole vibe, that's the assignment.
β¨ SYNOPSIS β¨
# use a fake LWP::Simple for testing from t/lib/LWP/Simple.pm
use mocked 'LWP::Simple';
my $text = get($url);
# use a fake WWW::Mechanize for testing from t/mock-libs/WWW/Mechanize.pm
use mocked [qw(WWW::Mechanize t/mock-libs)];
that's it. two lines. iconic. π«Ά
πΈ DESCRIPTION πΈ
so when you're doing unit testing, there's this thing that keeps happening β you need a mocked library to test those messy edge cases, or you just refuse to let your tests go off and hit slow code or external code. and honestly? valid.
that's where mocking libraries come in and they EAT every time. π₯
when you mock a library, you're making a fake one that gets used in place of the real one. the code can do as much or as little as is needed β your call, your rules, main character energy. π
and like, use mocked.pm as a safety measure (be sure you're actually using the mocked module, fr fr), and also as a way to document the tests for the future maintainers. they will thank you. they will. π
π VARIABLES π
real_inc_paths
the real @INC that we are over-ridding is stored here while we are loading the mocked library. she's holding the original receipts while the fake one does its thing. πβ¨
π FUNCTIONS π
import
with a package name, this function will ensure that the module you specify is loaded from t/lib. no cap. π§
you can also pass an array reference containing the package name and a directory from which to load it from. flexible. slay. π
π AUTHOR π
Luke Closs, <cpan at 5thplane.com> Scott McWhirter, <kungfuftr at cpan.org>
absolute legends, both of them. π«Ά
β MAD CREDS TO β
Ingy dΓΆt net, for only.pm β the way that this is the blueprint, iykyk. π
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
periodt. π
okay so that's the whole page, and just so you know exactly which version you're reading, it's perl v5.36.0 from 2022-12-04 β go forth and mock responsibly, bestie πΈπ¦π
π¦ where this page comes from
- debian bookworm: libmocked-perl 0.09-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmocked-perl 0.09-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmocked-perl 0.09-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmocked-perl 0.09-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmocked-perl 0.09-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms