| 1 | package Mnet::Version; | ||||||||||||
| 2 | |||||||||||||
| 3 | =head1 NAME | ||||||||||||
| 4 | |||||||||||||
| 5 | Mnet::Version - Returns Mnet version information | ||||||||||||
| 6 | |||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||
| 8 | |||||||||||||
| 9 | $info = Mnet::Version::info(); | ||||||||||||
| 10 | |||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||
| 12 | |||||||||||||
| 13 | Mnet::Version makes available an Mnet::Version::info function that can be used | ||||||||||||
| 14 | by other scripts and modules. | ||||||||||||
| 15 | |||||||||||||
| 16 | our $VERSION = "1.00"; | ||||||||||||
| 17 | |||||||||||||
| 18 | User scripts can use the above command to declare a version number string that | ||||||||||||
| 19 | will be detected by this module and included in its output. | ||||||||||||
| 20 | |||||||||||||
| 21 | =head1 FUNCTIONS | ||||||||||||
| 22 | |||||||||||||
| 23 | Mnet::Version implements the functions listed below. | ||||||||||||
| 24 | |||||||||||||
| 25 | =cut | ||||||||||||
| 26 | |||||||||||||
| 27 | # required modules | ||||||||||||
| 28 | 167 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | 167 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | 167 | ▶ | use Config; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | 167 | ▶ | use Cwd; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 167 | ▶ | use POSIX qw(uname); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | 167 | ▶ | use Mnet; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | |||||||||||||
| 37 | 150 | ▶ | sub info { | ||||||||||
|
Subroutine
info: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||
| 38 | |||||||||||||
| 39 | =head2 Mnet::Version::info | ||||||||||||
| 40 | |||||||||||||
| 41 | $info = Mnet::Version::info() | ||||||||||||
| 42 | |||||||||||||
| 43 | Output multiple lines of information about the current script, Mnet modules, | ||||||||||||
| 44 | and operating system. This is used by Mnet::Opts::Cli and Mnet::Log. | ||||||||||||
| 45 | |||||||||||||
| 46 | =cut | ||||||||||||
| 47 | |||||||||||||
| 48 | # note script name, without path | ||||||||||||
| 49 | 150 | my $script_name = $0; | |||||||||||
| 50 | 150 | $script_name =~ s/^.*\///; | |||||||||||
| 51 | |||||||||||||
| 52 | # note path to Mnet modules | ||||||||||||
| 53 | 150 | my $mnet_path = $INC{"Mnet/Version.pm"}; | |||||||||||
| 54 | 150 | $mnet_path =~ s/\/Mnet\/Version\.pm$//; | |||||||||||
| 55 | |||||||||||||
| 56 | # note path of currently running perl executable | ||||||||||||
| 57 | 150 | ▶ | my $perl_path = $Config{perlpath} // ""; | ||||||||||
|
Condition50%1/2
$Mnet::Version::Config{"perlpath"} // ""
MC/DC0%0/1
$Mnet::Version::Config{"perlpath"} // ""
$Mnet::Version::Config{"perlpath"}
Truth table50%1/2
A
A= $Mnet::Version::Config{"perlpath"}
| |||||||||||||
| 58 | |||||||||||||
| 59 | # note posix uname | ||||||||||||
| 60 | 150 | my @uname = POSIX::uname(); | |||||||||||
| 61 | 150 | my $uname = lc($uname[0]." ".$uname[2]); | |||||||||||
| 62 | |||||||||||||
| 63 | # note current working directory | ||||||||||||
| 64 | 150 | my $cwd_path = Cwd::getcwd(); | |||||||||||
| 65 | |||||||||||||
| 66 | # init output version info string, and sprintf pad string to align outputs | ||||||||||||
| 67 | 150 | my ($info, $spad) = ("", "15s"); | |||||||||||
| 68 | 150 | ▶ | $spad = "1s =" if caller eq "Mnet::Log"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | |||||||||||||
| 70 | # output caller script version if known, no blank line in Mnet::Log --debug | ||||||||||||
| 71 | 150 | ▶ | my $script_version = $main::VERSION // "?"; | ||||||||||
|
Condition50%1/2
$main::VERSION // "?"
MC/DC0%0/1
$main::VERSION // "?"
$main::VERSION
Truth table50%1/2
A
A= $main::VERSION
| |||||||||||||
| 72 | 150 | $info .= sprintf("%-$spad $script_version\n", "$script_name"); | |||||||||||
| 73 | 150 | ▶ | $info .= "\n" if caller ne "Mnet::Log"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | |||||||||||||
| 75 | # output mnet, perl, and os version, no blank line in Mnet::Log --debug | ||||||||||||
| 76 | 150 | $info .= sprintf("%-$spad $Mnet::VERSION\n", "Mnet version"); | |||||||||||
| 77 | 150 | $info .= sprintf("%-$spad $^V\n", "perl version"); | |||||||||||
| 78 | 150 | $info .= sprintf("%-$spad $uname\n", "system uname"); | |||||||||||
| 79 | 150 | ▶ | $info .= "\n" if caller ne "Mnet::Log"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | |||||||||||||
| 81 | # output path information, no blank line in Mnet::Log --debug | ||||||||||||
| 82 | 150 | $info .= sprintf("%-$spad $0\n", "exec path"); | |||||||||||
| 83 | 150 | $info .= sprintf("%-$spad $perl_path\n", "perl path"); | |||||||||||
| 84 | 150 | $info .= sprintf("%-$spad $mnet_path\n", "Mnet path"); | |||||||||||
| 85 | 150 | $info .= sprintf("%-$spad $cwd_path\n", "cwd path"); | |||||||||||
| 86 | |||||||||||||
| 87 | # finished Mnet::Version::info, return info string | ||||||||||||
| 88 | 150 | return $info; | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | |||||||||||||
| 92 | |||||||||||||
| 93 | =head1 SEE ALSO | ||||||||||||
| 94 | |||||||||||||
| 95 | L<Mnet> | ||||||||||||
| 96 | |||||||||||||
| 97 | =cut | ||||||||||||
| 98 | |||||||||||||
| 99 | # normal end of package | ||||||||||||
| 100 | 167 | 1; | |||||||||||
| 101 | |||||||||||||