Setup/Project/Functions.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« auto/share/dist/Setup-Project/tmpl/CLI/tmpl/__FLAVOR_NAME__.pl ↑ Summary Setup/Project.pm »
1 package Setup::Project::Functions;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 our @EXPORT = qw/
7 sharedir
8 scriptdir
9 equal_style
10 flavor_info
11 date
12 /;
13  
14 1 ▶use File::Spec::Functions ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 0 ▶use File::ShareDir ();
Subroutine BEGIN: called CC=1 SCAR=2.6
16 use Carp ();
17 use File::Basename ();
18 use Time::Piece;
19  
20 sub date {
21 sprintf "%s", (localtime)->datetime;
22 }
23  
24 sub flavor_info {
25 my $pkg = caller(0);
26 my $version = eval { $pkg->version };
27 $version ||= '';
28 sprintf "%s@%s", $pkg, $version;
29 }
30  
31 sub sharedir {
32 my ($package, @dir) = @_;
33 $package =~ s|::|-|;
34 File::Spec::Functions::catfile(File::ShareDir::dist_dir($package), @dir);
35 }
36  
37 sub scriptdir {
38 my (@dir) = @_;
39 File::Spec::Functions::catfile(File::Basename::dirname(File::Spec::Functions::rel2abs($0)), @dir);
40 }
41  
42 # name=1 author=hixi
43 sub equal_style {
44 my $argv = shift;
45 my %hash;
46 for my $var (@$argv) {
47 my ($key, $value) = map { trim($_) } split /=/, $var;
48 die "deplicated key: $key" if defined $hash{$key};
49 $hash{$key} = $value;
50 }
51 return %hash;
52 }
53  
54 sub trim {
55 s/^\s*(.*?)\s*$/$1/;
56 $_;
57 }
58  
59 1;
« auto/share/dist/Setup-Project/tmpl/CLI/tmpl/__FLAVOR_NAME__.pl ↑ Summary Setup/Project.pm »