1: <?php
2: declare(strict_types=1);
3: /**
4: * +------------------------------------------------------------+
5: * | apnscp |
6: * +------------------------------------------------------------+
7: * | Copyright (c) Apis Networks |
8: * +------------------------------------------------------------+
9: * | Licensed under Artistic License 2.0 |
10: * +------------------------------------------------------------+
11: * | Author: Matt Saladna (msaladna@apisnetworks.com) |
12: * +------------------------------------------------------------+
13: */
14:
15: /**
16: * @author Matt Saladna <matt@apisnetworks.com>
17: * @package core
18: */
19: class Perl_Module extends Module_Skeleton
20: {
21: public $exportedFunctions;
22:
23: public function __construct()
24: {
25: parent::__construct();
26: $this->exportedFunctions = array(
27: '*' => PRIVILEGE_ALL,
28: 'get_modules' => PRIVILEGE_SITE | PRIVILEGE_USER
29:
30: );
31: }
32:
33: public function get_modules()
34: {
35: $cmd = '/usr/bin/perl -e \'use File::Find;
36: foreach $start (@INC) { find(\&modules, $start); }
37: sub modules {
38: if (-d && /^[a-z]/) {
39: $File::Find::prune = 1; return; }
40: return unless /\.pm$/;
41: my $filename = "$File::Find::dir/$_";
42: $filename =~ s!^$start/!!;
43: $filename =~ s!\.pm\$!!;
44: $filename =~ s!/!::!g;
45: print "$filename\n";
46: }\' 2>&1';
47: $proc = Util_Process_Sudo::exec($cmd);
48: $perlArray = explode("\n", $proc['output']);
49: sort($perlArray);
50:
51: return $perlArray;
52: }
53:
54: /**
55: * string get_pod()
56: * Returns the POD for a specific Perl module
57: *
58: * @param string $module module name to return the documentation for
59: * @privilege PRIVILEGE_ALL
60: * @return string returns a string of the documentation if found; otherwise
61: * false is returned
62: */
63: public function get_pod($module)
64: {
65: $proc = Util_Process_Safe::exec('/usr/bin/perldoc %s', array($module));
66: $perlDoc = $proc['output'];
67:
68: return $perlDoc;
69: }
70:
71: /**
72: * string get_perl_version()
73: * Returns the version of the Perl interpreter
74: *
75: * @privilege PRIVILEGE_ALL
76: * @return string Perl version
77: */
78: public function version()
79: {
80: $cache = \Cache_Global::spawn();
81: $key = 'perl.version';
82: if (false === ($version = $cache->get($key))) {
83: $version = array_get(\Util_Process::exec(['/usr/bin/perl', '-e', 'printf "%vd", $^V;']), 'output');
84: $cache->set($key, $version);
85: }
86:
87: return $version;
88: }
89: }