'Initialize the environment for installing Perl packages.  The class is called during the initial
download stage when installing packages, so the value of initial_download will generally be True.
However, the parameter value allows this class to also be used in the second stage of the installation,
although it may never be necessary.  If initial_download is True, the recipe steps will be filtered
and returned and the installation directory (i.e., dir) will be defined and returned.  If we\'re not
in the initial download stage, these actions will not occur, and None values will be returned for them.'

def execute_step(self, tool_dependency, package_name, actions, action_dict, filtered_actions, env_file_builder, install_environment, work_dir, current_dir=None, initial_download=False):

    dir = None
    if initial_download:
        filtered_actions = actions[1:]
    env_shell_file_paths = action_dict.get('env_shell_file_paths', None)
    if (env_shell_file_paths is None):
        log.debug('Missing    Perl    environment,    make    sure    your    specified    Perl    installation    exists.')
        if initial_download:
            return (tool_dependency, filtered_actions, dir)
        return (tool_dependency, None, None)
    else:
        install_environment.add_env_shell_file_paths(env_shell_file_paths)
    log.debug(('Handling    setup_perl_environment    for    tool    dependency    %s    with    install_environment.env_shell_file_paths:\n%s' % (str(tool_dependency.name), str(install_environment.env_shell_file_paths))))
    dir = os.path.curdir
    current_dir = os.path.abspath(os.path.join(work_dir, dir))
    with lcd(current_dir):
        with settings(warn_only=True):
            perl_packages = action_dict.get('perl_packages', [])
            for perl_package_dict in perl_packages:
                perl_package = perl_package_dict['package']
                cmd = 'PERL_MM_USE_DEFAULT=1;    export    PERL_MM_USE_DEFAULT;    '
                cmd += ('HOME=%s;    export    HOME;    ' % work_dir)
                cmd += 'export    PERL5LIB=$INSTALL_DIR/lib/perl5:$PERL5LIB;'
                cmd += 'export    PATH=$INSTALL_DIR/bin:$PATH;'
                if (perl_package.find('://') != (-1)):
                    url = perl_package
                    perl_package_name = url.split('/')[(-1)]
                    checksums = perl_package_dict.get('checksums', {})
                    dir = self.url_download(work_dir, perl_package_name, url, extract=True, checksums=checksums)
                    tmp_work_dir = os.path.join(work_dir, dir)
                    if os.path.exists(os.path.join(tmp_work_dir, 'Makefile.PL')):
                        cmd += 'perl    Makefile.PL    INSTALL_BASE=$INSTALL_DIR    &&    make    &&    make    install'
                    elif os.path.exists(os.path.join(tmp_work_dir, 'Build.PL')):
                        cmd += 'perl    Build.PL    --install_base    $INSTALL_DIR    &&    perl    Build    &&    perl    Build    install'
                    else:
                        log.debug(('No    Makefile.PL    or    Build.PL    file    found    in    %s.    Skipping    installation    of    %s.' % (url, perl_package_name)))
                        if initial_download:
                            return (tool_dependency, filtered_actions, dir)
                        return (tool_dependency, None, None)
                    with lcd(tmp_work_dir):
                        cmd = install_environment.build_command(basic_util.evaluate_template(cmd, install_environment))
                        return_code = install_environment.handle_command(tool_dependency=tool_dependency, cmd=cmd, return_output=False, job_name=package_name)
                        if return_code:
                            if initial_download:
                                return (tool_dependency, filtered_actions, dir)
                            return (tool_dependency, None, None)
                else:
                    cmd += ('cpanm    --local-lib=$INSTALL_DIR    %s' % perl_package)
                    cmd = install_environment.build_command(basic_util.evaluate_template(cmd, install_environment))
                    return_code = install_environment.handle_command(tool_dependency=tool_dependency, cmd=cmd, return_output=False, job_name=package_name)
                    if return_code:
                        if initial_download:
                            return (tool_dependency, filtered_actions, dir)
                        return (tool_dependency, None, None)
            env_file_builder.handle_action_shell_file_paths(action_dict)
            env_file_builder.append_line(name='PERL5LIB', action='prepend_to', value=os.path.join(install_environment.install_dir, 'lib', 'perl5'))
            env_file_builder.append_line(name='PATH', action='prepend_to', value=os.path.join(install_environment.install_dir, 'bin'))
            return_code = env_file_builder.return_code
            if return_code:
                if initial_download:
                    return (tool_dependency, filtered_actions, dir)
                return (tool_dependency, None, None)
    if initial_download:
        return (tool_dependency, filtered_actions, dir)
    return (tool_dependency, None, None)
