diff options
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | lib/ManaTools/Shared.pm | 102 | ||||
-rw-r--r-- | t/08-Shared.t | 15 |
3 files changed, 106 insertions, 12 deletions
@@ -139,6 +139,7 @@ t/04-Shared_TimeZone.t t/05-rpmnew.t t/06-rpmdragora.t t/07-Shared_Services.t +t/08-Shared.t t/boilerplate.t t/manifest.t t/pod-coverage.t diff --git a/lib/ManaTools/Shared.pm b/lib/ManaTools/Shared.pm index 6a40539..feb2ebc 100644 --- a/lib/ManaTools/Shared.pm +++ b/lib/ManaTools/Shared.pm @@ -43,6 +43,9 @@ This module collects all the routines shared between ManaTools and its modules. disable_x_screensaver enable_x_screensaver isProcessRunning + custom_locale_dir + devel_mode + command_line =head1 SUPPORT @@ -79,13 +82,13 @@ along with this file. If not, see <http://www.gnu.org/licenses/>. use strict; use warnings; use diagnostics; +use feature 'state'; use Digest::MD5; use yui; use base qw(Exporter); -# TODO move GUI dialogs to Shared::GUI our @EXPORT_OK = qw( trim md5sum @@ -96,17 +99,21 @@ our @EXPORT_OK = qw( disable_x_screensaver enable_x_screensaver isProcessRunning + custom_locale_dir + devel_mode + command_line ); =head1 VERSION -Version 0.01 + Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; +# 2015-05-03 A.Naselli added locale_dir(), devel_mode() command_line() #============================================================= @@ -115,17 +122,17 @@ our $VERSION = '0.01'; =head3 PARAMETERS -$filename the name of the file to read + $filename the name of the file to read =head3 OUTPUT -depending from the context it returns the content -of the file as an array or a string + depending from the context it returns the content + of the file as an array or a string =head3 DESCRIPTION -This function return the content of $filename or false/0 -if it fails + This function return the content of $filename or false/0 + if it fails =cut @@ -150,13 +157,13 @@ sub apcat { =head3 OUTPUT -$distname: name of the distributed package + $distname: name of the distributed package =head3 DESCRIPTION -This function return the distname, useful to retrieve data -with File::ShareDir::dist_file and must be the same as into -Makefile.PL (e.g. manatools) + This function return the distname, useful to retrieve data + with File::ShareDir::dist_file and must be the same as into + Makefile.PL (e.g. manatools) =cut @@ -372,5 +379,76 @@ sub isProcessRunning { return; } +#============================================================= + +=head2 command_line + +=head3 OUTPUT + + $cmdline: given command line + +=head3 DESCRIPTION + + returns the command line meant as yui::YCommandLine object + +=cut + +#============================================================= +sub command_line() { + state $cmdline = new yui::YCommandLine; + + return $cmdline; +} + +# TODO evaluate if using state also for $pos into +# custom_locale_dir and devel_mode + +#============================================================= + +=head2 custom_locale_dir + +=head3 OUTPUT + + locale_dir: custom locale directory or undef + +=head3 DESCRIPTION + + returns the custom locale directory if given by + command line using "--locales-dir path" or undef + +=cut + +#============================================================= +sub custom_locale_dir() { + my $cmdline = ManaTools::Shared::command_line(); + my $pos = $cmdline->find("--locales-dir"); + + return ($pos > 0) ? $cmdline->arg($pos+1) : undef; +} + +#============================================================= + +=head2 devel_mode + +=head3 OUTPUT + + boolean: 1 if --devel-mode is passed to command line, 0 + otherwhise + +=head3 DESCRIPTION + + returns 1 if "--devel-mode" is passed to command line, + modules should check this value to work in developer mode + +=cut + +#============================================================= +sub devel_mode() { + my $cmdline = ManaTools::Shared::command_line(); + my $pos = $cmdline->find("--devel-mode"); + + return ($pos > 0) ? 1 : 0; +} + 1; # End of ManaTools::Shared diff --git a/t/08-Shared.t b/t/08-Shared.t new file mode 100644 index 0000000..3489a4a --- /dev/null +++ b/t/08-Shared.t @@ -0,0 +1,15 @@ +use 5.006; +use strict; +use warnings FATAL => 'all'; +use Test::More; + +BEGIN { + use_ok( 'ManaTools::Shared' ) || print "ManaTools::Shared failed!\n"; +} + +ok ( ManaTools::Shared::command_line(), 'command_line'); +is ( ManaTools::Shared::custom_locale_dir(), undef, 'custom_locale_dir'); +is ( ManaTools::Shared::devel_mode(), 0, 'devel_mode'); + + +done_testing; |