X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44..53593baa211863fbf66540cf1bcc36c8fb37257f:/SL/Version.pm diff --git a/SL/Version.pm b/SL/Version.pm new file mode 100644 index 000000000..f515721c5 --- /dev/null +++ b/SL/Version.pm @@ -0,0 +1,82 @@ +package SL::Version; + +use strict; + +our $instance; + +sub new { + bless \my $instace, __PACKAGE__; +} + +sub get_instance { + $instance //= $_[0]->new; +} + +sub get_version { + $$instance //= do { + open my $version_file, '<', "VERSION" or die 'can not open VERSION file'; + my $version = <$version_file>; + close $version_file; + + if ( -f "BUILD" ) { + open my $build_file, '<', "BUILD" or die 'can not open BUILD file'; + my $build = <$build_file>; + close $build_file; + $version .= '-' . $build; + } + + # only allow numbers, letters, points, underscores and dashes. Prevents injecting of malicious code. + $version =~ s/[^0-9A-Za-z\.\_\-]//g; + + $version; + } +} + +1; + +__END__ + +=encoding utf-8 + +=head1 NAME + +SL::Version + +=head1 SYNOPSIS + + use SL::Version; + + my $version = SL::Version->get_version + +=head1 DESCRIPTION + +This module is a singleton for the sole reason that SL::Form doesn't have to +cache the version. + +=head1 FUNCTIONS + +=head2 C + +Creates a new object. Should never be called. + +=head2 C + +Creates a singleton instance if none exists and returns. + +=head2 C + +Parses the version from the C file. + +If the file C exists, appends its contents as a build number. + +Returns a sanitized version string. + +=head1 BUGS + +None yet :) + +=head1 AUTHOR + +Sven Schöling Es.schoeling@linet-services.deE + +=cut