NAME

Java::Javap::TypeCast - map Java types to Perl 6 equivalents

SYNOPSIS

use Java::Javap::TypeCast;

$type_caster = Java::Javap::TypeCast->new();

$perl_type   = $type_caster->cast( $java_type );

DESCRIPTION

Provides a mechanism to map java type names (classes and interfaces) into corresponding perl type names (typically roles).

METHODS

new

$type_caster = Java::Javap::TypeCast->new();

Returns a new type caster instance with a default set of type casts.

The default set of type mappings should not be relied upon as it's likely to change over time with unpredictable results for your application. You should call "set_type_casts" and perhaps a method like "add_type_casts_from_file" to load in your own set of type mappings.

set_type_casts

$self->set_type_casts(\%hash)

Replaces the current set of type casts with the specified set.

add_type_casts

$self->add_type_casts(\%hash)

Adds the specified set of type casts to the current set, overriding any that have the same names.

add_type_casts_from_filehandle

$self->add_type_casts_from_filehandle($fh, $name)

Reads lines defining type mappings from the specified filehandle. Each is specified as two non-blank fields separated by whitespace. The first specified a Java type and the second a corresponding Perl type. Comments starting with a # character are ignored, as are blank lines.

A warning is issued for lines that aren't in the correct format. The $name argument is only used in that warnig message.

add_type_casts_from_file

$self->add_type_casts_from_file($filename)

Opens $filename for reading and calls "add_type_casts_from_filehandle".

cast

$perl_type = $type_caster->defined_cast( $java_type );

Returns a perl type for the corresponding java type argument if an type mapping has been defined, else undef.

Firstly the java type is looked up verbatim in the type mapping. If a defined value is found then it's returned.

If there's no verbatim match for the full type name then defined_cast() checks for wildcard matches by removing trailing words and appending a '*'. For example, if there's no entry for 'sun.lang.annotation.foo' the defined_cast() would look for each of these in turn:

sun.lang.annotation.foo
sun.lang.annotation.*
sun.lang.*
sun.*
*

fallback_cast()

$perl_type = $type_caster->cast( $java_type );

Returns a perl type for the corresponding java type argument by editing the java type name, without consulting the type mapping.

- dots are changed to double colons
- dollar symbols are changed to _PRIVATE_

cast

$perl_type = $type_caster->cast( $java_type );

Returns the result of calling "defined_cast", if defined, else returns the result of calling "fallback_cast".

AUTHOR

Tim Bunce, <tim.bunce@pobox.com>, Phil Crow, <crow.phil@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2010, Tim Bunce Copyright (C) 2007, Phil Crow

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.