<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Test2::Mock;
use strict;
use warnings;

our $VERSION = '0.000162';

use Carp qw/croak confess/;
our @CARP_NOT = (__PACKAGE__);

use Scalar::Util qw/weaken reftype blessed set_prototype/;
use Test2::Util qw/pkg_to_file/;
use Test2::Util::Stash qw/parse_symbol slot_to_sig get_symbol get_stash purge_symbol/;
use Test2::Util::Sub qw/gen_accessor gen_reader gen_writer/;

sub new; # Prevent hashbase from giving us 'new';
use Test2::Util::HashBase qw/class parent child _purge_on_destroy _blocked_load _symbols _track sub_tracking call_tracking/;

sub new {
    my $class = shift;

    croak "Called new() on a blessed instance, did you mean to call \$control-&gt;class-&gt;new()?"
        if blessed($class);

    my $self = bless({}, $class);

    $self-&gt;{+SUB_TRACKING}  ||= {};
    $self-&gt;{+CALL_TRACKING} ||= [];

    my @sets;
    while (my $arg = shift @_) {
        my $val = shift @_;

        if ($class-&gt;can(uc($arg))) {
            $self-&gt;{$arg} = $val;
            next;
        }

        push @sets =&gt; [$arg, $val];
    }

    croak "The 'class' field is required"
        unless $self-&gt;{+CLASS};

    for my $set (@sets) {
        my ($meth, $val) = @$set;
        my $type = reftype($val);

        confess "'$meth' is not a valid constructor argument for $class"
            unless $self-&gt;can($meth);

        if (!$type) {
            $self-&gt;$meth($val);
        }
        elsif($type eq 'HASH') {
            $self-&gt;$meth(%$val);
        }
        elsif($type eq 'ARRAY') {
            $self-&gt;$meth(@$val);
        }
        else {
            croak "'$val' is not a valid argument for '$meth'"
        }
    }

    return $self;
}

sub _check {
    return unless $_[0]-&gt;{+CHILD};
    croak "There is an active child controller, cannot proceed";
}

sub purge_on_destroy {
    my $self = shift;
    ($self-&gt;{+_PURGE_ON_DESTROY}) = @_ if @_;
    return $self-&gt;{+_PURGE_ON_DESTROY};
}

sub stash {
    my $self = shift;
    get_stash($self-&gt;{+CLASS});
}

sub file {
    my $self = shift;
    my $file = $self-&gt;class;
    return pkg_to_file($self-&gt;class);
}

sub block_load {
    my $self = shift;
    $self-&gt;_check();

    my $file = $self-&gt;file;

    croak "Cannot block the loading of module '" . $self-&gt;class . "', already loaded in file $INC{$file}"
        if $INC{$file};

    $INC{$file} = __FILE__;

    $self-&gt;{+_BLOCKED_LOAD} = 1;
}

my %NEW = (
    hash =&gt; sub {
        my ($class, %params) = @_;
        return bless \%params, $class;
    },
    array =&gt; sub {
        my ($class, @params) = @_;
        return bless \@params, $class;
    },
    ref =&gt; sub {
        my ($class, $params) = @_;
        return bless $params, $class;
    },
    ref_copy =&gt; sub {
        my ($class, $params) = @_;
        my $type = reftype($params);

        return bless {%$params}, $class
            if $type eq 'HASH';

        return bless [@$params], $class
            if $type eq 'ARRAY';

        croak "Not sure how to construct an '$class' from '$params'";
    },
);

sub override_constructor {
    my $self = shift;
    my ($name, $type) = @_;
    $self-&gt;_check();

    my $sub = $NEW{$type}
        || croak "'$type' is not a known constructor type";

    $self-&gt;override($name =&gt; $sub);
}

sub add_constructor {
    my $self = shift;
    my ($name, $type) = @_;
    $self-&gt;_check();

    my $sub = $NEW{$type}
        || croak "'$type' is not a known constructor type";

    $self-&gt;add($name =&gt; $sub);
}

sub autoload {
    my $self = shift;
    $self-&gt;_check();
    my $class = $self-&gt;class;
    my $stash = $self-&gt;stash;

    croak "Class '$class' already has an AUTOLOAD"
        if $stash-&gt;{AUTOLOAD} &amp;&amp; *{$stash-&gt;{AUTOLOAD}}{CODE};
    croak "Class '$class' already has an can"
        if $stash-&gt;{can} &amp;&amp; *{$stash-&gt;{can}}{CODE};

    # Weaken this reference so that AUTOLOAD does not prevent its own
    # destruction.
    weaken(my $c = $self);

    my ($file, $line) = (__FILE__, __LINE__ + 3);
    my $autoload = eval &lt;&lt;EOT || die "Failed generating AUTOLOAD sub: $@";
package $class;
#line $line "$file (Generated AUTOLOAD)"
our \$AUTOLOAD;
    sub {
        my (\$self) = \@_;
        my (\$pkg, \$name) = (\$AUTOLOAD =~ m/^(.*)::([^:]+)\$/g);
        \$AUTOLOAD = undef;

        return if \$name eq 'DESTROY';
        my \$sub = sub {
            my \$self = shift;
            (\$self-&gt;{\$name}) = \@_ if \@_;
            return \$self-&gt;{\$name};
        };

        \$c-&gt;add(\$name =&gt; \$sub);

        if (\$c-&gt;{_track}) {
            my \$call = {sub_name =&gt; \$name, sub_ref =&gt; \$sub, args =&gt; [\@_]};
            push \@{\$c-&gt;{sub_tracking}-&gt;{\$name}} =&gt; \$call;
            push \@{\$c-&gt;{call_tracking}} =&gt; \$call;
        }

        goto &amp;\$sub;
    }
EOT

    $line = __LINE__ + 3;
    my $can = eval &lt;&lt;EOT || die "Failed generating can method: $@";
package $class;
#line $line "$file (Generated can)"
use Scalar::Util 'reftype';
    sub {
        my (\$self, \$meth) = \@_;
        if (\$self-&gt;SUPER::can(\$meth)) {
            return \$self-&gt;SUPER::can(\$meth);
        }
        elsif (ref \$self &amp;&amp; reftype \$self eq 'HASH' &amp;&amp; exists \$self-&gt;{\$meth}) {
            return sub { shift-&gt;\$meth(\@_) };
        }
        return undef;
    }
EOT

    {
        local $self-&gt;{+_TRACK} = 0;
        $self-&gt;add(AUTOLOAD =&gt; $autoload);
        $self-&gt;add(can =&gt; $can);
    }
}

sub before {
    my $self = shift;
    my ($name, $sub) = @_;
    $self-&gt;_check();
    my $orig = $self-&gt;current($name, required =&gt; 1);
    $self-&gt;_inject({}, $name =&gt; set_prototype(sub { $sub-&gt;(@_); $orig-&gt;(@_) }, prototype $sub));
}

sub after {
    my $self = shift;
    my ($name, $sub) = @_;
    $self-&gt;_check();
    my $orig = $self-&gt;current($name, required =&gt; 1);
    $self-&gt;_inject(
        {},
        $name =&gt; set_prototype(
            sub {
                my @out;

                my $want = wantarray;

                if ($want) {
                    @out = $orig-&gt;(@_);
                }
                elsif (defined $want) {
                    $out[0] = $orig-&gt;(@_);
                }
                else {
                    $orig-&gt;(@_);
                }

                $sub-&gt;(@_);

                return @out    if $want;
                return $out[0] if defined $want;
                return;
            },
            prototype $sub,
        )
    );
}

sub around {
    my $self = shift;
    my ($name, $sub) = @_;
    $self-&gt;_check();
    my $orig = $self-&gt;current($name, required =&gt; 1);
    $self-&gt;_inject({}, $name =&gt; set_prototype(sub { $sub-&gt;($orig, @_) }, prototype $sub));
}

sub add {
    my $self = shift;
    $self-&gt;_check();
    $self-&gt;_inject({add =&gt; 1}, @_);
}

sub override {
    my $self = shift;
    $self-&gt;_check();
    $self-&gt;_inject({}, @_);
}

sub set {
    my $self = shift;
    $self-&gt;_check();
    $self-&gt;_inject({set =&gt; 1}, @_);
}

sub current {
    my $self = shift;
    my ($sym, %params) = @_;

    my $out = get_symbol($sym, $self-&gt;{+CLASS});
    return $out unless $params{required};
    confess "Attempt to modify a sub that does not exist '$self-&gt;{+CLASS}\::$sym' (Mock operates on packages, not classes, are you looking for a symbol in a parent class?)"
        unless $out;
    return $out;
}

sub orig {
    my $self = shift;
    my ($sym) = @_;

    $sym = "&amp;$sym" unless $sym =~ m/^[&amp;\$\%\@]/;

    my $syms = $self-&gt;{+_SYMBOLS}
        or croak "No symbols have been mocked yet";

    my $ref = $syms-&gt;{$sym};

    croak "Symbol '$sym' is not mocked"
        unless $ref &amp;&amp; @$ref;

    my ($orig) = @$ref;

    return $orig;
}

sub track {
    my $self = shift;

    ($self-&gt;{+_TRACK}) = @_ if @_;

    return $self-&gt;{+_TRACK};
}

sub clear_call_tracking { @{shift-&gt;{+CALL_TRACKING}} = () }

sub clear_sub_tracking {
    my $self = shift;

    unless (@_) {
        %{$self-&gt;{+SUB_TRACKING}} = ();
        return;
    }

    for my $item (@_) {
        delete $self-&gt;{+SUB_TRACKING}-&gt;{$item};
    }

    return;
}

sub _parse_inject {
    my $self = shift;
    my ($param, $arg) = @_;

    if ($param =~ m/^-(.*)$/) {
        my $sym = $1;
        my $sig = slot_to_sig(reftype($arg));
        my $ref = $arg;
        return ($sig, $sym, $ref);
    }

    return ('&amp;', $param, $arg)
        if ref($arg) &amp;&amp; reftype($arg) eq 'CODE';

    my ($is, $field, $val);

    if(defined($arg) &amp;&amp; !ref($arg) &amp;&amp; $arg =~ m/^(rw|ro|wo)$/) {
        $is    = $arg;
        $field = $param;
    }
    elsif (!ref($arg)) {
        $val = $arg;
        $is  = 'val';
    }
    elsif (reftype($arg) eq 'HASH') {
        $field = delete $arg-&gt;{field} || $param;

        $val = delete $arg-&gt;{val};
        $is  = delete $arg-&gt;{is};

        croak "Cannot specify 'is' and 'val' together" if $val &amp;&amp; $is;

        $is ||= $val ? 'val' : 'rw';

        croak "The following keys are not valid when defining a mocked sub with a hashref: " . join(", " =&gt; keys %$arg)
            if keys %$arg;
    }
    else {
        confess "'$arg' is not a valid argument when defining a mocked sub";
    }

    my $sub;
    if ($is eq 'rw') {
        $sub = gen_accessor($field);
    }
    elsif ($is eq 'ro') {
        $sub = gen_reader($field);
    }
    elsif ($is eq 'wo') {
        $sub = gen_writer($field);
    }
    else { # val
        $sub = sub { $val };
    }

    return ('&amp;', $param, $sub);
}

sub _inject {
    my $self = shift;
    my ($params, @pairs) = @_;

    my $add = $params-&gt;{add};
    my $set = $params-&gt;{set};

    my $class = $self-&gt;{+CLASS};

    $self-&gt;{+_SYMBOLS} ||= {};
    my $syms = $self-&gt;{+_SYMBOLS};

    while (my $param = shift @pairs) {
        my $arg = shift @pairs;
        my ($sig, $sym, $ref) = $self-&gt;_parse_inject($param, $arg);
        my $orig = $self-&gt;current("$sig$sym");

        croak "Cannot override '$sig$class\::$sym', symbol is not already defined"
            unless $orig || $add || $set || ($sig eq '&amp;' &amp;&amp; $class-&gt;can($sym));

        # Cannot be too sure about scalars in globs
        croak "Cannot add '$sig$class\::$sym', symbol is already defined"
            if $add &amp;&amp; $orig
            &amp;&amp; (reftype($orig) ne 'SCALAR' || defined($$orig));

        $syms-&gt;{"$sig$sym"} ||= [];
        push @{$syms-&gt;{"$sig$sym"}} =&gt; $orig; # Might be undef, thats expected

        if ($self-&gt;{+_TRACK} &amp;&amp; $sig eq '&amp;') {
            my $sub_tracker  = $self-&gt;{+SUB_TRACKING};
            my $call_tracker = $self-&gt;{+CALL_TRACKING};
            my $sub = $ref;
            $ref = sub {
                my $call = {sub_name =&gt; $sym, sub_ref =&gt; $sub, args =&gt; [@_]};
                push @{$sub_tracker-&gt;{$param}} =&gt; $call;
                push @$call_tracker =&gt; $call;
                goto &amp;$sub;
            };
        }

        no strict 'refs';
        no warnings 'redefine';
        *{"$class\::$sym"} = $ref;
    }

    return;
}

sub _set_or_unset {
    my $self = shift;
    my ($symbol, $set) = @_;

    my $class = $self-&gt;{+CLASS};

    return purge_symbol($symbol, $class)
        unless $set;

    my $sym = parse_symbol($symbol, $class);
    no strict 'refs';
    no warnings 'redefine';
    *{"$class\::$sym-&gt;{name}"} = $set;
}

sub restore {
    my $self = shift;
    my ($sym) = @_;
    $self-&gt;_check();

    $sym = "&amp;$sym" unless $sym =~ m/^[&amp;\$\%\@]/;

    my $syms = $self-&gt;{+_SYMBOLS}
        or croak "No symbols are mocked";

    my $ref = $syms-&gt;{$sym};

    croak "Symbol '$sym' is not mocked"
        unless $ref &amp;&amp; @$ref;

    my $old = pop @$ref;
    delete $syms-&gt;{$sym} unless @$ref;

    return $self-&gt;_set_or_unset($sym, $old);
}

sub reset {
    my $self = shift;
    my ($sym) = @_;
    $self-&gt;_check();

    $sym = "&amp;$sym" unless $sym =~ m/^[&amp;\$\%\@]/;

    my $syms = $self-&gt;{+_SYMBOLS}
        or croak "No symbols are mocked";

    my $ref = delete $syms-&gt;{$sym};

    croak "Symbol '$sym' is not mocked"
        unless $ref &amp;&amp; @$ref;

    my ($old) = @$ref;

    return $self-&gt;_set_or_unset($sym, $old);
}

sub reset_all {
    my $self = shift;
    $self-&gt;_check();

    my $syms = $self-&gt;{+_SYMBOLS} || return;

    $self-&gt;reset($_) for keys %$syms;

    delete $self-&gt;{+_SYMBOLS};
}

sub _purge {
    my $self = shift;
    my $stash = $self-&gt;stash;
    delete $stash-&gt;{$_} for keys %$stash;
}

sub DESTROY {
    my $self = shift;

    delete $self-&gt;{+CHILD};
    $self-&gt;reset_all if $self-&gt;{+_SYMBOLS};

    delete $INC{$self-&gt;file} if $self-&gt;{+_BLOCKED_LOAD};

    $self-&gt;_purge if $self-&gt;{+_PURGE_ON_DESTROY};
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Test2::Mock - Module for managing mocked classes and instances.

=head1 DESCRIPTION

This module lets you add and override methods for any package temporarily. When
the instance is destroyed it will restore the package to its original state.

=head1 SYNOPSIS

    use Test2::Mock;
    use MyClass;

    my $mock = Test2::Mock-&gt;new(
        track =&gt; $BOOL, # enable call tracking if desired
        class =&gt; 'MyClass',
        override =&gt; [
            name =&gt; sub { 'fred' },
            ...
        ],
        add =&gt; [
            is_mocked =&gt; sub { 1 }
            ...
        ],
        ...
    );

    # Unmock the 'name' sub
    $mock-&gt;restore('name');

    ...

    $mock = undef; # Will remove all the mocking

=head1 CONSTRUCTION

=head1 METHODS

=over 4

=item $mock = Test2::Mock-&gt;new(class =&gt; $CLASS, ...)

This will create a new instance of L&lt;Test2::Mock&gt; that manages mocking
for the specified C&lt;$CLASS&gt;.

Any C&lt;Test2::Mock&gt; method can be used as a constructor argument, each
should be followed by an arrayref of arguments to be used within the method. For
instance the C&lt;add()&gt; method:

    my $mock = Test2::Mock-&gt;new(
        class =&gt; 'AClass',
        add =&gt; [foo =&gt; sub { 'foo' }],
    );

is identical to this:

    my $mock = Test2::Mock-&gt;new(
        class =&gt; 'AClass',
    );
    $mock-&gt;add(foo =&gt; sub { 'foo' });

=item $mock-&gt;track($bool)

Turn tracking on or off. Any sub added/overridden/set when tracking is on will
log every call in a hash retrievable via C&lt;&lt; $mock-&gt;tracking &gt;&gt;. Changing the
tracking toggle will not affect subs already altered, but will affect any
additional alterations.

=item $hashref = $mock-&gt;sub_tracking

The tracking data looks like this:

    {
        sub_name =&gt; [
            {sub_name =&gt; $sub_name, sub_ref =&gt; $mock_subref, args =&gt; [... copy of @_ from the call ... ]},
            ...,
            ...,
        ],
    }

Unlike call_tracking, this lists all calls by sub, so you can choose to only
look at the sub specific calls.

B&lt;Please note:&gt; The hashref items with the subname and args are shared with
call_tracking, modifying one modifies the other, so copy first!

=item $arrayref = $mock-&gt;call_tracking

The tracking data looks like this:

    [
        {sub_name =&gt; $sub_name, sub_ref =&gt; $mock_subref, args =&gt; [... copy of @_ from the call ... ]},
        ...,
        ...,
    ]

Unlike sub_tracking this lists all calls to any mocked sub, in the order they
were called. To filter by sub use sub_tracking.

B&lt;Please note:&gt; The hashref items with the subname and args are shared with
sub_tracking, modifying one modifies the other, so copy first!

=item $mock-&gt;clear_sub_tracking()

=item $mock-&gt;clear_sub_tracking(\@subnames)

Clear tracking data. With no arguments ALL tracking data is cleared. When
arguments are provided then only those specific keys will be cleared.

=item $mock-&gt;clear_call_tracking()

Clear all items from call_tracking.

=item $mock-&gt;add('symbol' =&gt; ..., 'symbol2' =&gt; ...)

=item $mock-&gt;override('symbol1' =&gt; ..., 'symbol2' =&gt; ...)

=item $mock-&gt;set('symbol1' =&gt; ..., 'symbol2' =&gt; ...)

C&lt;add()&gt; and C&lt;override()&gt; are the primary ways to add/modify methods for a
class. Both accept the exact same type of arguments. The difference is that
C&lt;override&gt; will fail unless the symbol you are overriding already exists,
C&lt;add&gt; on the other hand will fail if the symbol does already exist.

C&lt;set()&gt; was more recently added for cases where you may not know if the sub
already exists. These cases are rare, and set should be avoided (think of it
like 'no strict'). However there are valid use cases, so it was added.

B&lt;Note:&gt; Think of override as a push operation. If you call override on the
same symbol multiple times it will track that. You can use C&lt;restore()&gt; as a
pop operation to go back to the previous mock. C&lt;reset&gt; can be used to remove
all the mocking for a symbol.

Arguments must be a symbol name, with optional sigil, followed by a new
specification of the symbol. If no sigil is specified then '&amp;' (sub) is
assumed. A simple example of overriding a sub:

    $mock-&gt;override(foo =&gt; sub { 'overridden foo' });
    my $val = $class-&gt;foo; # Runs our override
    # $val is now set to 'overridden foo'

You can also simply provide a value and it will be wrapped in a sub for you:

    $mock-&gt;override( foo =&gt; 'foo' );

The example above will generate a sub that always returns the string 'foo'.

There are three *special* values that can be used to generate accessors:

    $mock-&gt;add(
        name =&gt; 'rw',   # Generates a read/write accessor
        age  =&gt; 'ro',   # Generates a read only accessor
        size =&gt; 'wo',   # Generates a write only accessor
    );

If you want to have a sub that actually returns one of the three special strings, or
that returns a coderef, you can use a hashref as the spec:

    my $ref = sub { 'my sub' };
    $mock-&gt;add(
        rw_string =&gt; { val =&gt; 'rw' },
        ro_string =&gt; { val =&gt; 'ro' },
        wo_string =&gt; { val =&gt; 'wo' },
        coderef   =&gt; { val =&gt; $ref }, # the coderef method returns $ref each time
    );

You can also override/add other symbol types, such as hash:

    package Foo;
    ...

    $mock-&gt;add('%foo' =&gt; {a =&gt; 1});

    print $Foo::foo{a}; # prints '1'

You can also tell mock to deduce the symbol type for the add/override from the
reference, rules are similar to glob assignments:

    $mock-&gt;add(
        -foo =&gt; sub { 'foo' },     # Adds the &amp;foo sub to the package
        -foo =&gt; { foo =&gt; 1 },      # Adds the %foo hash to the package
        -foo =&gt; [ 'f', 'o', 'o' ], # Adds the @foo array to the package
        -foo =&gt; \"foo",            # Adds the $foo scalar to the package
    );

=item $mock-&gt;restore($SYMBOL)

Restore the symbol to what it was before the last override. If the symbol was
recently added this will remove it. If the symbol has been overridden multiple
times this will ONLY restore it to the previous state. Think of C&lt;override&gt; as a
push operation, and C&lt;restore&gt; as the pop operation.

=item $mock-&gt;reset($SYMBOL)

Remove all mocking of the symbol and restore the original symbol. If the symbol
was initially added then it will be completely removed.

=item $mock-&gt;orig($SYMBOL)

This will return the original symbol, before any mocking. For symbols that were
added this will return undef.

=item $mock-&gt;current($SYMBOL)

This will return the current symbol.

=item $mock-&gt;reset_all

Remove all added symbols, and restore all overridden symbols to their originals.

=item $mock-&gt;add_constructor($NAME =&gt; $TYPE)

=item $mock-&gt;override_constructor($NAME =&gt; $TYPE)

This can be used to inject constructors. The first argument should be the name
of the constructor. The second argument specifies the constructor type.

The C&lt;hash&gt; type is the most common, all arguments are used to create a new
hash that is blessed.

    hash =&gt; sub  {
        my ($class, %params) = @_;
        return bless \%params, $class;
    };

The C&lt;array&gt; type is similar to the hash type, but accepts a list instead of
key/value pairs:

    array =&gt; sub {
        my ($class, @params) = @_;
        return bless \@params, $class;
    };

The C&lt;ref&gt; type takes a reference and blesses it. This will modify your
original input argument.

    ref =&gt; sub {
        my ($class, $params) = @_;
        return bless $params, $class;
    };

The C&lt;ref_copy&gt; type will copy your reference and bless the copy:

    ref_copy =&gt; sub {
        my ($class, $params) = @_;
        my $type = reftype($params);

        return bless {%$params}, $class
            if $type eq 'HASH';

        return bless [@$params], $class
            if $type eq 'ARRAY';

        croak "Not sure how to construct a '$class' from '$params'";
    };

=item $mock-&gt;before($NAME, sub { ... })

This will replace the original sub C&lt;$NAME&gt; with a new sub that calls your
custom code just before calling the original method. The return from your
custom sub is ignored. Your sub and the original both get the unmodified
arguments.

=item $mock-&gt;after($NAME, sub { ... })

This is similar to before, except your callback runs after the original code.
The return from your callback is ignored.

=item $mock-&gt;around($NAME, sub { ... })

This gives you the chance to wrap the original sub:

    $mock-&gt;around(foo =&gt; sub {
        my $orig = shift;
        my $self = shift;
        my (@args) = @_;

        ...
        $self-&gt;$orig(@args);
        ...

        return ...;
    });

The original sub is passed in as the first argument, even before C&lt;$self&gt;. You
are responsible for making sure your wrapper sub returns the correct thing.

=item $mock-&gt;autoload

This will inject an C&lt;AUTOLOAD&gt; sub into the class. This autoload will
automatically generate read-write accessors for any sub called that does not
already exist.

=item $mock-&gt;block_load

This will prevent the real class from loading until the mock is destroyed. This
will fail if the class is already loaded. This will let you mock a class
completely without loading the original module.

=item $pm_file = $mock-&gt;file

This returns the relative path to the file for the module. This corresponds to
the C&lt;%INC&gt; entry.

=item $bool = $mock-&gt;purge_on_destroy($bool)

When true, this will cause the package stash to be completely obliterated when
the mock object falls out of scope or is otherwise destroyed. You do not
normally want this.

=item $stash = $mock-&gt;stash

This returns the stash for the class being mocked. This is the equivalent of:

    my $stash = \%{"${class}\::"};

This saves you from needing to turn off strict.

=item $class = $mock-&gt;class

The class being mocked by this instance.

=item $p = $mock-&gt;parent

If you mock a class twice the first instance is the parent, the second is the
child. This prevents the parent from being destroyed before the child, which
would lead to a very unpleasant situation.

=item $c = $mock-&gt;child

Returns the child mock, if any.

=back

=head1 SOURCE

The source code repository for Test2-Suite can be found at
L&lt;https://github.com/Test-More/Test2-Suite/&gt;.

=head1 MAINTAINERS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 AUTHORS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 COPYRIGHT

Copyright 2018 Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

See L&lt;https://dev.perl.org/licenses/&gt;

=cut
</pre></body></html>