Template-Plugin-Java

 view release on metacpan or  search on metacpan

lib/Template/Plugin/Java/Utils.pm  view on Meta::CPAN

=cut
sub sqlType2JavaType ($;$) {
	($_, my $precision) = @_;

	/^.*char$/i	&& return 'String';
	/^integer$/i	&& return 'int';
	/^bigint$/i	&& return 'long';
	/^smallint$/i	&& return 'short';

	/^numeric$/i	&& do {
		$precision <= 5	&& return 'short';
		$precision <= 10&& return 'int';
				   return 'long';
	};

	/^date$/i	&& return 'Date';

	return 'byte[]';
}

=item B<simplifyPath( path )>

Remove any dir/../ or /./ or extraneous / from a path, as well as prepending
the current directory if necessary.

=cut
sub simplifyPath ($) {
	use URI::file;
	my $path = shift;

	return URI::file->new_abs($path)->file;
}

=item B<findPackageDir( directory )>

Find package in $ENV{CLASSPATH}.

=cut
sub findPackageDir ($) {
	my $package	= shift;
	my $classpath	= $ENV{CLASSPATH};
	my @classpath	= split /:/, $classpath;
	my @package	= split /\./, $package;
	my $package_dir	= join ("/", @package) . "/";

# Find the first match in CLASSPATH.
	for (map { "$_/$package_dir" } @classpath) {
		return $_ if -d;
	}

	return "";
}

=item B<determinePackage([ optional directory ])>

Determine the package of the current or passed-in directory.

=cut
sub determinePackage (;$) {
	my $dir = shift || ".";
	my @cwd = split m|/|, substr ( simplifyPath $dir, 1 );

	my $i = @cwd;
	while ($i--) {
		my $package = join ('.', @cwd[$i..$#cwd]);

		if (findPackageDir $package) {
			return $package;
		}
	}

	return join ('.', @cwd);	# If all else fails.
}

=item B<isNum( string )>

Determines whether a string is a number or not. Uses the more powerful
DBI::looks_like_number heuristic if available.

=cut
my $isNum_body;
eval { require DBI };
if (not $@ && DBI->can('looks_like_number')) {
	$isNum_body = sub {
		if (DBI::looks_like_number( shift )) {
			return TRUE;
		} else {
			return FALSE;
		}
	};
} else {
	$isNum_body = sub {
		local $^W = undef if $^W;
		$_	  = shift;

		if (not defined $_) {
			return FALSE;
		} elsif ($_ != 0 or /^0*(?:\.0*)$/) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
}

# Install the sub reference as the sub.
{
	no strict 'refs';

	*{__PACKAGE__.'::isNum'} = $isNum_body;
}

=item B<castJavaString( variable_name, target_type )>

Casts a java String to another type using the appropriate code.

=cut
sub castJavaString {
	my ($name, $type) = @_;

	for ($type) {



( run in 2.184 seconds using v1.01-cache-2.11-cpan-71847e10f99 )