| 1 | #Region "Microsoft.VisualBasic::d0cec6f2541f38cfb128872b266ea3ce, Microsoft.VisualBasic.Core\CommandLine\InteropService\SharedORM\Perl.vb" |
| 2 | |
| 3 | ' Author: |
| 4 | ' |
| 5 | ' asuka (amethyst.asuka@gcmodeller.org) |
| 6 | ' xie (genetics@smrucc.org) |
| 7 | ' xieguigang (xie.guigang@live.com) |
| 8 | ' |
| 9 | ' Copyright (c) 2018 GPL3 Licensed |
| 10 | ' |
| 11 | ' |
| 12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
| 13 | ' |
| 14 | ' |
| 15 | ' This program is free software: you can redistribute it and/or modify |
| 16 | ' it under the terms of the GNU General Public License as published by |
| 17 | ' the Free Software Foundation, either version 3 of the License, or |
| 18 | ' (at your option) any later version. |
| 19 | ' |
| 20 | ' This program is distributed in the hope that it will be useful, |
| 21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | ' GNU General Public License for more details. |
| 24 | ' |
| 25 | ' You should have received a copy of the GNU General Public License |
| 26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | |
| 28 | |
| 29 | |
| 30 | ' /********************************************************************************/ |
| 31 | |
| 32 | ' Summaries: |
| 33 | |
| 34 | ' Class Perl |
| 35 | ' |
| 36 | ' Constructor: (+1 Overloads) Sub New |
| 37 | ' Function: GetSourceCode |
| 38 | ' |
| 39 | ' |
| 40 | ' /********************************************************************************/ |
| 41 | |
| 42 | #End Region |
| 43 | |
| 44 | Imports System.Text |
| 45 | |
| 46 | Namespace CommandLine.InteropService.SharedORM |
| 47 | |
| 48 | ''' <summary> |
| 49 | ''' 为了构建GCModeller的脚本自动化而构建的源代码生成器,生成``perl module(*.pm)`` |
| 50 | ''' </summary> |
| 51 | Public Class Perl : Inherits CodeGenerator |
| 52 | |
| 53 | Dim namespace$ |
| 54 | |
| 55 | ' #!/usr/bin/perl |
| 56 | ' ' package assemblyName; |
| 57 | ' ' sub new { |
| 58 | ' ' my $class = shift; |
| 59 | ' my $self = { |
| 60 | ' ' _memberField1 => shift, |
| 61 | ' _memberField2 => shift, |
| 62 | ' ' }; |
| 63 | ' ' bless $self, $class; |
| 64 | ' return $self; |
| 65 | ' } |
| 66 | ' ' sub public_function { |
| 67 | ' ' my ($self, $arg1, $arg2) = @_; |
| 68 | ' ' # using class member |
| 69 | ' # |
| 70 | ' # get value |
| 71 | ' my $m1 = $self->{_memberField1}; |
| 72 | ' |
| 73 | ' # set value |
| 74 | ' $self->{_memberField1} = $arg1; |
| 75 | ' } |
| 76 | ' ' sub readonly_property { |
| 77 | ' my ($self) = @_; |
| 78 | ' |
| 79 | ' # return field value |
| 80 | ' return $self->{_memberField2}; |
| 81 | ' } |
| 82 | ' ' |
| 83 | ' # usage |
| 84 | ' ' #!/usr/bin/perl |
| 85 | ' ' use assemblyName; |
| 86 | ' ' my $App = new assemblyName(); |
| 87 | ' ' # invoke |
| 88 | ' $App->public_function($arg1, $arg2); |
| 89 | ' ' # get property value |
| 90 | ' my $value = $App->readonly_property(); |
| 91 | |
| 92 | Public Sub New(CLI As Type, namespace$) |
| 93 | MyBase.New(CLI) |
| 94 | Me.namespace = [namespace] |
| 95 | End Sub |
| 96 | |
| 97 | Public Overrides Function GetSourceCode() As String |
| 98 | Dim perl As New StringBuilder |
| 99 | |
| 100 | Call perl.AppendLine("#!/usr/bin/perl") |
| 101 | Call perl.AppendLine() |
| 102 | |
| 103 | Call perl.AppendLine($"package {exe};") |
| 104 | |
| 105 | Call perl.AppendLine("sub new {") |
| 106 | Call perl.AppendLine("my $class = shift;") |
| 107 | Call perl.AppendLine("my $self = {") |
| 108 | Call perl.AppendLine(" path = shift") |
| 109 | Call perl.AppendLine("};") |
| 110 | Call perl.AppendLine("bless $self, $class;") |
| 111 | Call perl.AppendLine("return $self;") |
| 112 | Call perl.AppendLine("}") |
| 113 | |
| 114 | Return perl.ToString |
| 115 | End Function |
| 116 | End Class |
| 117 | End Namespace |