line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of App-PythonToPerl |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is Copyright (c) 2023 by Auto-Parallel Technologies, Inc. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software, licensed under: |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# The GNU General Public License, Version 3, June 2007 |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# [[[ HEADER ]]] |
11
|
|
|
|
|
|
|
# ABSTRACT: a shebang, denoting an executable script |
12
|
|
|
|
|
|
|
#use RPerl; |
13
|
|
|
|
|
|
|
package Python::Shebang; |
14
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
15
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
16
|
|
|
|
|
|
|
our $VERSION = 0.001_000; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# [[[ OO INHERITANCE ]]] |
19
|
1
|
|
|
1
|
|
17
|
use parent qw(Python::Component); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
20
|
1
|
|
|
1
|
|
103
|
use Python::Component; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
22
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# [[[ CRITICS ]]] |
23
|
|
|
|
|
|
|
## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print op |
24
|
|
|
|
|
|
|
## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils |
25
|
|
|
|
|
|
|
## no critic qw(ProhibitConstantPragma ProhibitMagicNumbers) # USER DEFAULT 3: allow constants |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# [[[ INCLUDES ]]] |
28
|
1
|
|
|
1
|
|
9
|
use Perl::Types; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
545
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# [[[ OO PROPERTIES ]]] |
31
|
|
|
|
|
|
|
our hashref $properties = { |
32
|
|
|
|
|
|
|
component_type => my string $TYPED_component_type = 'Python::Shebang', |
33
|
|
|
|
|
|
|
python_line_number_begin => my integer $TYPED_python_line_number_begin = undef, |
34
|
|
|
|
|
|
|
python_line_number_end => my integer $TYPED_python_line_number_end = undef, |
35
|
|
|
|
|
|
|
python_source_code => my string $TYPED_python_source_code = undef, |
36
|
|
|
|
|
|
|
perl_source_code => my string $TYPED_perl_source_code = undef, |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# [[[ SUBROUTINES & OO METHODS ]]] |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# PYSH01x |
42
|
|
|
|
|
|
|
sub python_preparsed_to_perl_source { |
43
|
|
|
|
|
|
|
# return translated Perl source code for pre-parsed Python component |
44
|
0
|
|
|
0
|
0
|
|
{ my string $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
( my Python::Shebang $self, my OpenAI::API $openai ) = @ARG; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# error if no OpenAI API |
48
|
0
|
0
|
|
|
|
|
if (not defined $openai) { |
49
|
0
|
|
|
|
|
|
croak 'ERROR EPYSH010: undefined OpenAI API, croaking'; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# error or warning if no Python source code |
53
|
0
|
0
|
0
|
|
|
|
if ((not exists $self->{python_source_code}) or |
|
|
|
0
|
|
|
|
|
54
|
|
|
|
|
|
|
(not defined $self->{python_source_code}) or |
55
|
|
|
|
|
|
|
($self->{python_source_code} eq q{})) { |
56
|
0
|
|
|
|
|
|
croak 'ERROR EPYSH011: non-existent or undefined or empty Python source code, croaking'; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# $self->{perl_source_code} = '#!/usr/bin/perl'; # HARD-CODED OLD STYLE, MAY NOT WORK ON ALL OPERATING SYSTEMS? |
60
|
0
|
|
|
|
|
|
$self->{perl_source_code} = '#!/usr/bin/env perl'; # SOFT-CODED NEW STYLE, SHOULD WORK ON ALL OPERATING SYSTEMS? |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
print 'in Function::Shebang->python_preparsed_to_perl_source(), about to return $self->{perl_source_code} = \'', $self->{perl_source_code}, '\'', "\n"; |
63
|
|
|
|
|
|
|
#die 'TMP DEBUG'; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# return Perl source code |
66
|
0
|
|
|
|
|
|
return $self->{perl_source_code}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |