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: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 
<?php
    declare(strict_types=1);
    /**
     *  +------------------------------------------------------------+
     *  | apnscp                                                     |
     *  +------------------------------------------------------------+
     *  | Copyright (c) Apis Networks                                |
     *  +------------------------------------------------------------+
     *  | Licensed under Artistic License 2.0                        |
     *  +------------------------------------------------------------+
     *  | Author: Matt Saladna (msaladna@apisnetworks.com)           |
     *  +------------------------------------------------------------+
     */

    /**
     * @author  Matt Saladna <matt@apisnetworks.com>
     * @package core
     */
    class Perl_Module extends Module_Skeleton
    {
        public $exportedFunctions;

        public function __construct()
        {
            parent::__construct();
            $this->exportedFunctions = array(
                '*'           => PRIVILEGE_ALL,
                'get_modules' => PRIVILEGE_SITE | PRIVILEGE_USER

            );
        }

        public function get_modules()
        {
            $cmd = '/usr/bin/perl -e \'use File::Find;
                foreach $start (@INC) { find(\&modules, $start); }
                sub modules {
                if (-d && /^[a-z]/) {
                $File::Find::prune = 1; return; }
                return unless /\.pm$/;
                my $filename = "$File::Find::dir/$_";
                $filename =~ s!^$start/!!;
                $filename =~ s!\.pm\$!!;
                $filename =~ s!/!::!g;
                print "$filename\n";
                }\' 2>&1';
            $proc = Util_Process_Sudo::exec($cmd);
            $perlArray = explode("\n", $proc['output']);
            sort($perlArray);

            return $perlArray;
        }

        /**
         * string get_pod()
         * Returns the POD for a specific Perl module
         *
         * @param string $module module name to return the documentation for
         * @privilege PRIVILEGE_ALL
         * @return string returns a string of the documentation if found; otherwise
         *                       false is returned
         */
        public function get_pod($module)
        {
            $proc = Util_Process_Safe::exec('/usr/bin/perldoc %s', array($module));
            $perlDoc = $proc['output'];

            return $perlDoc;
        }

        /**
         * string get_perl_version()
         * Returns the version of the Perl interpreter
         *
         * @privilege PRIVILEGE_ALL
         * @return string Perl version
         */
        public function version()
        {
            $version = Util_Process::exec("/usr/bin/perl -e 'printf \"%vd\", \$^V;'");

            return $version['output'];
        }
    }

?>