lib/Chj/IsPerl.pm

filter: Statementstmt 66.6% 24 / 36 Branchbran 7.1% 1 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 7 totaltotal 47.8% 33 / 69 CC 8 SCAR 22.9
CC
8
Cov
50%
is_perl_exe_shebang
30.0
is_perl_script_path
6.0
is_perl_exe
6.0
CRAP 9.8
« lib/FP/Docstring.pm ↑ Summary lib/FP/Repl.pm »
1 #
2 # Copyright (c) 2019-2020 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::IsPerl
13  
14 =head1 SYNOPSIS
15  
16 1 ▶ use Chj::IsPerl qw(is_perl_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 is is_perl_file(__FILE__), 1;
18  
19 =head1 DESCRIPTION
20  
21 Report whether a file is (primarily) holding Perl code.
22  
23 =head1 NOTE
24  
25 This is alpha software! Read the status section in the package README
26 or on the L<website|http://functional-perl.org/>.
27  
28 =cut
29  
30 package Chj::IsPerl;
31 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 2 our @EXPORT_OK = qw(
37 is_perl_exe_shebang
38 is_perl_module_path
39 is_perl_script_path
40 is_perl_module
41 is_perl_exe
42 is_perl_file
43 );
44  
45 0 ▶sub fh_looks_perlish {
Subroutine fh_looks_perlish: not called CC=1 SCAR=6.9
Pod undocumented
46 0 0 # don't go there, OK?
47 }
48  
49 2 my $perl_re = qr(perl(?:5(?:\.\d+.*)?)?);
50  
51 0 ▶sub is_perl_exe_shebang {
Subroutine is_perl_exe_shebang: not called CC=5 SCAR=34.0
Pod undocumented
52 0 my ($path) = @_;
53 0 ▶ open my $in, "<", $path or die "'$path': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $path or die "'${path}': $!" 0 0 0
54 0 my $head = <$in>;
55 0 ▶ defined $head or die "'$path': $!";
Branch: 1 branch
BranchTrueFalseTotal
defined $head or die "'${path}': $!" 0 0 0
56 0 ▶ if (my ($exe, $rest) = $head =~ m!^#\!(\S+)\s+(.*)!s) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $head =~ /^#!(\S+)\s+(.*)/s) { } 0 0 0
57 0 ▶ ($exe =~ m!(^|/)$perl_re\z!s or $rest =~ m!(^|\S+/)$perl_re(?:\s|\z)!s)
Branch: 1 branch
BranchTrueFalseTotal
$exe =~ m[(^|/)$perl_re\z]s or $rest =~ m[(^|\S+/)$perl_re(?:\s|\z)]s 0 0 0
58 } else {
59 0 0
60 }
61 }
62  
63 1 ▶sub is_perl_module_path {
Subroutine is_perl_module_path: called CC=1 SCAR=0.0
Pod undocumented
64 1 my ($path) = @_;
65 1 scalar $path =~ m!\w\.pm\z!s
66 }
67  
68 0 ▶sub is_perl_script_path {
Subroutine is_perl_script_path: not called CC=2 SCAR=17.9
Pod undocumented
69 0 my ($path) = @_;
70 0 ▶ $path =~ m!\w\.pl\z!s or $path =~ m!(?:^|/)Makefile.PL\z!si
Branch: 1 branch
BranchTrueFalseTotal
$path =~ /\w\.pl\z/s or $path =~ m[(?:^|/)Makefile.PL\z]is 0 0 0
71 }
72  
73 # And the main API:
74  
75 1 ▶sub is_perl_module {
Subroutine is_perl_module: called CC=1 SCAR=0.0
Pod undocumented
76 1 my ($path) = @_;
77 1 is_perl_module_path $path
78 }
79  
80 0 ▶sub is_perl_exe {
Subroutine is_perl_exe: not called CC=2 SCAR=17.9
Pod undocumented
81 0 my ($path) = @_;
82 0 ▶ is_perl_script_path $path or is_perl_exe_shebang $path
Branch: 1 branch
BranchTrueFalseTotal
is_perl_script_path($path) or is_perl_exe_shebang($path) 0 0 0
83 }
84  
85 1 ▶sub is_perl_file {
Subroutine is_perl_file: called CC=2 SCAR=7.2
Pod undocumented
86 1 my ($path) = @_;
87 1 ▶ is_perl_module $path or is_perl_exe $path
Branch: 1 branch
BranchTrueFalseTotal
is_perl_module($path) or is_perl_exe($path) 1 0 1
88 }
89  
90 2 1
« lib/FP/Docstring.pm ↑ Summary lib/FP/Repl.pm »