File: ua_trap.t

package info (click to toggle)
libmetacpan-client-perl 2.033000-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 552 kB
  • sloc: perl: 2,564; makefile: 6
file content (52 lines) | stat: -rw-r--r-- 945 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
46
47
48
49
50
51
52
use strict;
use warnings;

use Test::More;

# ABSTRACT: Make sure passed value of UA gets used for things.

use Test::Needs {
    'WWW::Mechanize::Cached' => 1.54,
    'HTTP::Tiny::Mech'       => 1.001002,
};
use Test::Fatal qw( exception );

{

    package TrapUA;
    our $VERSION = '0.01';
    use Moo;
    extends 'HTTP::Tiny::Mech';

    sub mechua {
        require WWW::Mechanize::Cached;
        return WWW::Mechanize::Cached->new();
    }
}

{
    require HTTP::Tiny;
    no warnings "redefine";
    *HTTP::Tiny::request = sub {
        my ( $self, @args ) = @_;
        die "Illegal use of HTTP::Tiny" . pp( \@args );
    };
}
use MetaCPAN::Client;

my $e;
is(
    $e = exception {
        my $client = MetaCPAN::Client->new( ua => TrapUA->new() );

        my $a        = $client->author('KENTNL');
        my $releases = $a->releases;
    },
    undef,
    "No illegal methods called"
);

if ($e) { diag explain $e }

done_testing;