From: Justin Hunter Date: Tue, 8 Sep 2009 19:12:48 +0000 (-0700) Subject: put former S::T::Utils method parse_mysql_version into Translator.pm as engine_version X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ffe3a4b12b524bc762c3e61922fa3695e2adb522;p=dbsrgits%2FSQL-Translator-2.0-ish.git put former S::T::Utils method parse_mysql_version into Translator.pm as engine_version --- diff --git a/lib/SQL/Translator.pm b/lib/SQL/Translator.pm index f1fc0f0..f9083fa 100644 --- a/lib/SQL/Translator.pm +++ b/lib/SQL/Translator.pm @@ -114,4 +114,38 @@ class SQL::Translator { method parser_type { return $self->parser } method producer_type { return $self->producer } + + method engine_version(Int|Str $v, Str $target = 'perl') { + my @vers; + + # X.Y.Z style + if ( $v =~ / ^ (\d+) \. (\d{1,3}) (?: \. (\d{1,3}) )? $ /x ) { + push @vers, $1, $2, $3; + } + + # XYYZZ (mysql) style + elsif ( $v =~ / ^ (\d) (\d{2}) (\d{2}) $ /x ) { + push @vers, $1, $2, $3; + } + + # XX.YYYZZZ (perl) style or simply X + elsif ( $v =~ / ^ (\d+) (?: \. (\d{3}) (\d{3}) )? $ /x ) { + push @vers, $1, $2, $3; + } + else { + #how do I croak sanely here? + die "Unparseable MySQL version '$v'"; + } + + if ($target eq 'perl') { + return sprintf ('%d.%03d%03d', map { $_ || 0 } (@vers) ); + } + elsif ($target eq 'mysql') { + return sprintf ('%d%02d%02d', map { $_ || 0 } (@vers) ); + } + else { + #how do I croak sanely here? + die "Unknown version target '$target'"; + } + } }