[英]How do I convert these 4 SQL tables into OO Classes (Java or C#) but not with NHibernate/LINQ?
[英]How can I convert OO Perl to Java?
我繼承了OO Perl代碼的大型單片體,需要逐步轉換為Java(根據客戶端請求)。 我知道這兩種語言,但我的Perl技能生銹了。 有沒有人可以推薦的工具(Eclipse插件?)來緩解疼痛?
OO代碼是否使用Moose? 如果是,則可以使用內省自動轉換類聲明。
要逐步將Perl轉換為Java,可以使用Inline :: Java將Java代碼包含到Perl程序中。
我說PLEAC是最好的資源之一。
inccode.com允許您自動將perl代碼轉換為java代碼。 然而,由於perl中的動態類型,perl變量的轉換有點棘手。 perl中的標量變量可以包含對任何類型的引用,並且在執行代碼時已知真實引用的類型。
Translator使用VarBox類封裝所有預定義類型:ref(HASH),ref(ARRAY)和BoxModule,用於封裝對Perl模塊的引用。
示例顯示perl腳本,它調用兩個模塊來打印“hello world”。 模塊LibConsole在腳本中實例化,模塊LibPrinter通過調用LibConsole中的方法來訪問。
#!/usr/bin/perl
use strict;
use test::LibPrinter;
use test::LibConsole;
hello_on_console( "hello world");
hello_on_printer( "hello world");
sub get_console
{
my $console = test::LibConsole->new();
return $console;
}
sub get_printer
{
#@cast(module="test::LibPrinter")
my $printer = get_console()->get_printer();
return $printer;
}
sub hello_on_console
{
my ($hello) = @_;
my $console = get_console();
$console->output ($hello);
}
sub hello_on_printer
{
my ($hello) = @_;
my $printer= get_printer();
$printer->output ($hello);
}
轉換器現在必須是兩個模塊的類型,而perl沒有定義用於聲明對象的特定運算符,假設名為“new”的方法返回對模塊的引用。 當返回對模塊返回引用的方法時,注釋強制轉換(module =“{class}”)可用於通知轉換器有關模塊類型的信息。
由於翻譯器控制分配中類型的一致性,因此將傳播已識別的變量類型。
public class hello extends CRoutineProcess implements IInProcess
{
VarBox call ()
{
hello_on_console("hello world");
return hello_on_printer("hello world");
}
BoxModule<LibConsole> get_console ()
{
BoxModule<LibConsole> varConsole = new BoxModule<LibConsole>(LibConsole.apply());
return varConsole;
}
BoxModule<test.LibPrinter> get_printer ()
{
BoxModule<LibPrinter> varPrinter = new BoxModule<LibPrinter>(get_console().getModule().get_printer());
return varPrinter;
}
VarBox hello_on_console (VarBox varHello)
{
BoxModule<LibConsole> varConsole = new BoxModule<LibConsole>(get_console());
return varConsole.getModule().output(varHello);
}
VarBox hello_on_printer (VarBox varHello)
{
BoxModule<LibPrinter> varPrinter = new BoxModule<LibPrinter>(get_printer());
return varPrinter.getModule().output(varHello);
}
}
翻譯的代碼需要執行運行時庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.