File Coverage

blib/lib/RPerl/AfterSubclass.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             # DEV NOTE: all code originally in RPerl.pm, moved here when filter() added, now called in code generated by filter()
2              
3             # [[[ HEADER ]]]
4             package RPerl::AfterSubclass;
5 9     9   70532 use strict;
  9         25  
  9         1037  
6 9     9   58 use warnings;
  9         24  
  9         490  
7             our $VERSION = 0.003_000;
8              
9             # [[[ INCLUDES ]]]
10 9     9   4848 use RPerl::CompileUnit::Module::Class;
  0            
  0            
11             1; # end of package
12              
13              
14             # [[[ HEADER ]]]
15             package RPerl;
16             use strict;
17             use warnings;
18              
19             # [[[ INCLUDES ]]]
20             use File::Basename;
21              
22             # [[[ INCLUDES SPECIAL ]]]
23             require RPerl::Config;
24             #use RPerl::Config;
25              
26             #BEGIN { use Data::Dumper; print 'in RPerl::AfterSubclass, have @INC = ' . "\n" . Dumper(\@INC) . "\n"; }
27              
28             #no magic; # require data types, full declarations, other non-magic
29             # DEV NOTE, CORRELATION #rp008: circular dependency causes "subroutine FOO redefined" errors, solved by replacing use with require below
30             #use rperltypes;
31             require rperltypes;
32             #require rperloperations;
33             #require rperlrules;
34             require rperlnames;
35             #require rperlnamespaces;
36              
37             # NEED ADD: use/require HelperFunctions*.pm here (not just in rperltypes.pm) to match dependency path of C++ code?
38              
39             # [[[ CONSTANTS ]]]
40             #use constant TEST_CONSTANT => my string $TYPED_TEST_CONSTANT = 'Hello, World!';
41             use constant TEST_CONSTANT => 'Hello, World!';
42              
43             # [[[ SUBROUTINES ]]]
44              
45             sub package_to_namespace_root {
46             ( my $package ) = @_;
47             # print {*STDERR} 'in RPerl::package_to_namespace_root(), received $package = ' . $package . "\n";
48              
49             my $namespace_root = q{};
50             my $package_split = [ ( split /::/, $package ) ];
51             if ( ( defined $package_split->[0] ) and ( $package_split->[0] ne q{} ) ) {
52             $namespace_root = $package_split->[0] . '::';
53             }
54              
55             # print {*STDERR} 'in RPerl::package_to_namespace_root(), about to return $namespace_root = ' . $namespace_root . "\n";
56             return $namespace_root;
57             }
58              
59             sub filename_short_to_namespace_root_guess {
60             ( my $filename_short ) = @_;
61             # print {*STDERR} 'in RPerl::filename_short_to_namespace_root_guess(), received $filename_short = ' . $filename_short . "\n";
62             # # DEV NOTE, CORRELATION #rp021: remove hard-coded fake 'rperl::' namespace?
63             if ($filename_short eq 'rperl') { return 'rperl::'; }
64             my $namespace_root = q{};
65             ( my $filename_prefix, my $filename_path, my $filename_suffix ) = fileparse( $filename_short, qr/[.][^.]*/xms );
66             # DEV NOTE: allow *.pl files to guess a namespace instead of empty string, both here and in filename_short_to_package_guess() below
67             # due to Perl core and/or RPerl deps calls to 'use' or 'require' *.pl files, such as Config_git.pl and Config_heavy.pl
68             # if ( $filename_suffix eq '.pm' ) {
69             if ( ( $filename_suffix eq '.pm' ) or ( $filename_suffix eq '.pl' ) ) {
70             my $filename_path_split;
71             if ( $OSNAME eq 'MSWin32' ) {
72             $filename_path_split = [ split /[\/\\]/, $filename_path ];
73             #absolute paths cant go through here anymore, this was dropping the
74             #first part of the package on some modules
75             #shift @{$filename_path_split}; # discard leading drive letter
76             }
77             else {
78             $filename_path_split = [ split /\//, $filename_path ];
79             }
80              
81             # join then re-split in case there are no directories in path, only the *.pm filename
82             my $namespace_root_split = [ split /::/, ( join '::', ( @{$filename_path_split}, $filename_prefix ) ) ];
83             if ( $namespace_root_split->[0] eq '.' ) {
84             shift @{$namespace_root_split};
85             }
86             # print {*STDERR} 'in RPerl::filename_short_to_namespace_root_guess(), have $namespace_root_split = ' . Dumper($namespace_root_split) . "\n";
87             $namespace_root = $namespace_root_split->[0] . '::';
88             }
89             # print {*STDERR} 'in RPerl::filename_short_to_namespace_root_guess(), about to return $namespace_root = ' . $namespace_root . "\n";
90             return $namespace_root;
91             }
92              
93             sub filename_short_to_package_guess {
94             ( my $filename_short ) = @_;
95             # print {*STDERR} 'in RPerl::filename_short_to_package_guess(), received $filename_short = ' . $filename_short . "\n";
96             my $package = q{};
97             ( my $filename_prefix, my $filename_path, my $filename_suffix ) = fileparse( $filename_short, qr/[.][^.]*/xms );
98              
99             # print {*STDERR} 'in RPerl::filename_short_to_package_guess(), have $filename_prefix = ' . $filename_prefix . "\n";
100             # print {*STDERR} 'in RPerl::filename_short_to_package_guess(), have $filename_path = ' . $filename_path . "\n";
101             # print {*STDERR} 'in RPerl::filename_short_to_package_guess(), have $filename_suffix = ' . $filename_suffix . "\n";
102              
103             # if ( $filename_suffix eq '.pm' ) {
104             if ( ( $filename_suffix eq '.pm' ) or ( $filename_suffix eq '.pl' ) ) {
105             my $filename_path_split;
106             if ( $OSNAME eq 'MSWin32' ) {
107             $filename_path_split = [ split /\\/, $filename_path ];
108             shift @{$filename_path_split}; # discard leading drive letter
109             }
110             else {
111             $filename_path_split = [ split /\//, $filename_path ];
112             }
113             if ($filename_path_split->[0] eq '.') {
114             shift @{$filename_path_split};
115             }
116             # print {*STDERR} 'in RPerl::filename_short_to_package_guess(), have $filename_path_split = ' . Dumper($filename_path_split) . "\n";
117             $package = join '::', ( @{$filename_path_split}, $filename_prefix );
118             }
119             # print {*STDERR} 'in RPerl::filename_short_to_package_guess(), about to return $package = ' . $package . "\n";
120             return $package;
121             }
122              
123             1; # end of package