File Coverage

blib/lib/RPerl/AfterSubclass.pm
Criterion Covered Total %
statement 42 60 70.0
branch 7 16 43.7
condition 4 9 44.4
subroutine 9 10 90.0
pod 0 3 0.0
total 62 98 63.2


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   63841 use strict;
  9         20  
  9         1290  
6 9     9   53 use warnings;
  9         17  
  9         408  
7             our $VERSION = 0.003_000;
8              
9             # [[[ INCLUDES ]]]
10 9     9   4603 use RPerl::CompileUnit::Module::Class;
  9         30  
  9         315  
11             1; # end of package
12              
13              
14             # [[[ HEADER ]]]
15             package RPerl;
16 9     9   67 use strict;
  9         16  
  9         191  
17 9     9   42 use warnings;
  9         20  
  9         247  
18              
19             # [[[ INCLUDES ]]]
20 9     9   55 use File::Basename;
  9         1877  
  9         779  
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 9     9   61 use constant TEST_CONSTANT => 'Hello, World!';
  9         20  
  9         3916  
42              
43             # [[[ SUBROUTINES ]]]
44              
45             sub package_to_namespace_root {
46 32     32 0 147 ( my $package ) = @_;
47             # print {*STDERR} 'in RPerl::package_to_namespace_root(), received $package = ' . $package . "\n";
48              
49 32         112 my $namespace_root = q{};
50 32         191 my $package_split = [ ( split /::/, $package ) ];
51 32 50 33     345 if ( ( defined $package_split->[0] ) and ( $package_split->[0] ne q{} ) ) {
52 32         113 $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 32         143 return $namespace_root;
57             }
58              
59             sub filename_short_to_namespace_root_guess {
60 20247     20247 0 39099 ( 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 20247 50       42706 if ($filename_short eq 'rperl') { return 'rperl::'; }
  0         0  
64 20247         31373 my $namespace_root = q{};
65 20247         319585 ( 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 20247 100 100     76781 if ( ( $filename_suffix eq '.pm' ) or ( $filename_suffix eq '.pl' ) ) {
70 20216         29084 my $filename_path_split;
71 20216 50       43870 if ( $OSNAME eq 'MSWin32' ) {
72 0         0 $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 20216         55904 $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 20216         33948 my $namespace_root_split = [ split /::/, ( join '::', ( @{$filename_path_split}, $filename_prefix ) ) ];
  20216         72958  
83 20216 100       55087 if ( $namespace_root_split->[0] eq '.' ) {
84 1923         2700 shift @{$namespace_root_split};
  1923         3229  
85             }
86             # print {*STDERR} 'in RPerl::filename_short_to_namespace_root_guess(), have $namespace_root_split = ' . Dumper($namespace_root_split) . "\n";
87 20216         42131 $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 20247         50488 return $namespace_root;
91             }
92              
93             sub filename_short_to_package_guess {
94 0     0 0   ( my $filename_short ) = @_;
95             # print {*STDERR} 'in RPerl::filename_short_to_package_guess(), received $filename_short = ' . $filename_short . "\n";
96 0           my $package = q{};
97 0           ( 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 0 0 0       if ( ( $filename_suffix eq '.pm' ) or ( $filename_suffix eq '.pl' ) ) {
105 0           my $filename_path_split;
106 0 0         if ( $OSNAME eq 'MSWin32' ) {
107 0           $filename_path_split = [ split /\\/, $filename_path ];
108 0           shift @{$filename_path_split}; # discard leading drive letter
  0            
109             }
110             else {
111 0           $filename_path_split = [ split /\//, $filename_path ];
112             }
113 0 0         if ($filename_path_split->[0] eq '.') {
114 0           shift @{$filename_path_split};
  0            
115             }
116             # print {*STDERR} 'in RPerl::filename_short_to_package_guess(), have $filename_path_split = ' . Dumper($filename_path_split) . "\n";
117 0           $package = join '::', ( @{$filename_path_split}, $filename_prefix );
  0            
118             }
119             # print {*STDERR} 'in RPerl::filename_short_to_package_guess(), about to return $package = ' . $package . "\n";
120 0           return $package;
121             }
122              
123             1; # end of package