lib/Chj/Package/OfPath.pm

filter: Statementstmt 42.0% 21 / 50 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 2 totaltotal 32.9% 27 / 82 CC 12 SCAR 38.5
CC
12
Cov
29%
package_of_path
90.0
package_of_path_or_package
20.0
BEGIN
1.0
CRAP 47.2
« lib/FP/RegexMatch.pm ↑ Summary lib/Chj/IO/Tempdir.pm »
1 #
2 # Copyright (c) 2006-2014 Christian Jaeger, copying@christianjaeger.ch
3 #
4 # This is free software, offered under either the same terms as perl 5
5 # or the terms of the Artistic License version 2 or the terms of the
6 # MIT License (Expat version). See the file COPYING.md that came
7 # bundled with this file.
8 #
9  
10 =head1 NAME
11  
12 Chj::Package::OfPath
13  
14 =head1 SYNOPSIS
15  
16 =head1 DESCRIPTION
17  
18 (Taken from chj-bin's perl_path2namespace.)
19  
20  
21 =head1 NOTE
22  
23 This is alpha software! Read the status section in the package README
24 or on the L<website|http://functional-perl.org/>.
25  
26 =cut
27  
28 package Chj::Package::OfPath;
29 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Chj::singlequote;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 our @EXPORT_OK = qw(
37 package_of_path
38 package_of_path_or_package
39 );
40  
41 1 our $DEBUG = 0;
42  
43 0 ▶sub package_of_path {
Subroutine package_of_path: not called CC=9 SCAR=45.0
Pod undocumented
44 0 my ($path) = @_;
45 0 $path =~ s{^\./}{};
46 0 my $class = $path;
47 0 $class =~ s/\.pm$//;
48 0 $class =~ s|/|::|sg;
49 0 ▶ if ($path =~ m{^/}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[^/]) { } 0 0 0
50  
51 # absolute
52 } else {
53 0 ▶ my $p = abs_path $path or die "abs_path '$path': $!";
Branch: 1 branch
BranchTrueFalseTotal
my $p = abs_path($path) or die "abs_path '${path}': $!" 0 0 0
54 0 $path = $p;
55 }
56 0 ▶ warn "path=" . singlequote($path) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Chj::Package::OfPath::DEBUG 0 0 0
57  
58 0 ▶ open my $in, "<", $path or die "could not open '$path': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $path or die "could not open '${path}': $!" 0 0 0
59  
60 0 local $/;
61 0 my $content = <$in>;
62 0 ▶ close $in or die "closing '$path': $!";
Branch: 1 branch
BranchTrueFalseTotal
close $in or die "closing '${path}': $!" 0 0 0
63 CHECK: {
64 0 ▶ while ($content =~ m{\bpackage +([\w:]+)}g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\bpackage +([\w:]+)/g) 0 0 0
65 0 my $namespace = $1;
66 0 ▶ if ($class =~ m/\Q$namespace\E$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /\Q$namespace\E$/) 0 0 0
67 0 ▶ warn "cutting '$class' down to '$namespace'\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Chj::Package::OfPath::DEBUG 0 0 0
68 0 $class = $namespace;
69 0 last CHECK;
70 }
71 }
72 0 die "could not find any package definition in '$path' "
73 . "matching its path";
74 }
75 $class
76 0 }
77  
78 0 ▶sub package_of_path_or_package {
Subroutine package_of_path_or_package: not called CC=4 SCAR=30.0
Pod undocumented
79 0 my ($path_or_package) = @_;
80 0 ▶ if ($path_or_package =~ m{(\S+\.pm)}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($path_or_package =~ /(\S+\.pm)/) { } 0 0 0
elsif ($path_or_package =~ /^(\w+\:\:)*\w+\z/s) { } 0 0 0
elsif ($path_or_package =~ m[^(\w+/)*\w+\z]s) { } 0 0 0
81 0 package_of_path($1)
82 } elsif ($path_or_package =~ m{^(\w+\:\:)*\w+\z}s) {
83 0 $path_or_package
84 } elsif ($path_or_package =~ m{^(\w+/)*\w+\z}s) {
85 0 $path_or_package =~ s|/|::|sg;
86 0 $path_or_package
87 } else {
88 0 die "doesn't look sane: " . singlequote($path_or_package)
89 }
90 }
91  
92 1 1
« lib/FP/RegexMatch.pm ↑ Summary lib/Chj/IO/Tempdir.pm »