package TestBase;

# Copyright 2020 cPanel, L. L. C.
# All rights reserved.
# http://cpanel.net
#
# This is free software; you can redistribute it and/or modify it under the
# same terms as Perl itself. See L<perlartistic>.

use strict;
use warnings;
use autodie;

use mro;

use parent 'Test::Class';

use Test::More;

use cPanel::APIClient;

sub fail_if_returned_early { 1 }

sub SKIP_CLASS {
    my ($class) = @_;

    my $classes_ar = mro::get_linear_isa($class);

    for my $class (@$classes_ar) {
        my @reqs = $class->can('_CP_REQUIRE') ? $class->_CP_REQUIRE() : ();

        for my $req (@reqs) {
            local $@;

            my $ok = ref($req) ? eval { $req->(); 1 } : eval "require $req; 1";

            return $@ if !$ok;
        }
    }

    return q<>;
}

sub CREATE {
    my ( $self, @args ) = @_;

    my $remote_cp = cPanel::APIClient->create(
        transport => $self->TRANSPORT(),

        @args,
    );

    return $remote_cp;
}

1;
