CGI-Lingua

 view release on metacpan or  search on metacpan

t/data-flow.t  view on Meta::CPAN

#!/usr/bin/env perl

# t/data-flow.t -- CGI::Lingua data-flow tests.
#
# Validates Define-Use (DU) chains, resource lifecycles, and global-variable
# non-pollution throughout the module.  Each section identifies which variable
# or resource is under test, the DU anomaly class being hunted (D~, DD, ~U,
# O~) and the specific invariant being asserted.
#
# Network I/O is blocked globally; individual subtests install narrow mocks
# as needed and call _block_network() immediately after restore_all().

use strict;
use warnings;

use CHI;
use JSON::PP ();
use Readonly;
use Scalar::Util qw(blessed);
use Test::Most;
use Test::Mockingbird;
use Test::Without::Module qw(IP::Country);

BEGIN { use_ok('CGI::Lingua') }

# ── Pre-require lazy-loaded modules before any mocking ────────────────────────
# A module's BEGIN block runs on first require and would clobber mocks installed
# before that point.  Load unconditionally so the symbol table is stable.
my $HAS_LWP  = eval { require LWP::Simple::WithCache; 1 } ? 1 : 0;
my $HAS_JSON = eval { require JSON::Parse;             1 } ? 1 : 0;

# ── Constants ─────────────────────────────────────────────────────────────────

Readonly my %LANG => (
	EN    => 'en',
	EN_GB => 'en-gb',
	EN_US => 'en-us',
	FR    => 'fr',
	DE    => 'de',
);

Readonly my %IP => (
	PUBLIC   => '8.8.8.8',
	PRIVATE  => '192.168.1.1',
	LOOPBACK => '127.0.0.1',
	MAPPED   => '::ffff:8.8.8.8',       # IPv4-mapped IPv6
	MAPPED_BAD => '::ffff:999.0.0.1',   # IPv4-mapped but octets out of range
	BAIDU    => '185.10.105.1',          # inside Baidu /22 subnet
	NON_BAIDU_EU => '185.10.103.1',      # adjacent /22 block — not Baidu
);

# Country codes used as GEOIP_COUNTRY_CODE / CF header values
Readonly my $CC_GB => 'GB';
Readonly my $CC_US => 'US';
Readonly my $CC_DE => 'DE';

# ── Global network block ──────────────────────────────────────────────────────

_block_network();

# ── Helpers ───────────────────────────────────────────────────────────────────

sub _block_network {
	Test::Mockingbird::mock('CGI::Lingua', '_resolve_country_via_whois', sub { });
	Test::Mockingbird::mock('LWP::Simple::WithCache', 'get', sub { undef })
		if $HAS_LWP;
}

sub _obj {
	my ($supported, %extra) = @_;



( run in 1.571 second using v1.01-cache-2.11-cpan-800906f7e73 )