File Coverage

blib/lib/Modern/Perl/Prelude.pm
Criterion Covered Total %
statement 60 60 100.0
branch 8 8 100.0
condition n/a
subroutine 14 14 100.0
pod n/a
total 82 82 100.0


line stmt bran cond sub pod time code
1             package Modern::Perl::Prelude;
2              
3 5     5   1302610 use v5.30;
  5         23  
4 5     5   32 use strict;
  5         9  
  5         188  
5 5     5   30 use warnings;
  5         14  
  5         488  
6              
7             # ABSTRACT: Project prelude for modern Perl style on Perl 5.30+
8             our $VERSION = '0.005';
9              
10 5     5   3162 use Import::Into ();
  5         19765  
  5         160  
11 5     5   38 use strict ();
  5         11  
  5         98  
12 5     5   25 use warnings ();
  5         10  
  5         84  
13 5     5   28 use feature ();
  5         9  
  5         77  
14 5     5   1772 use utf8 ();
  5         1141  
  5         119  
15              
16 5     5   3350 use Feature::Compat::Try ();
  5         2217  
  5         156  
17 5     5   2976 use builtin::compat ();
  5         126889  
  5         3333  
18              
19             my @FEATURES = qw(
20             say
21             state
22             fc
23             );
24              
25             my @BUILTINS = qw(
26             blessed
27             refaddr
28             reftype
29             trim
30             ceil
31             floor
32             true
33             false
34             weaken
35             unweaken
36             is_weak
37             );
38              
39             my %KNOWN_ARG = map { $_ => 1 } qw(
40             -utf8
41             -class
42             -defer
43             );
44              
45             sub import {
46 11     11   10203 my ($class, @args) = @_;
47 11         37 my %arg = _parse_args(@args);
48 10         59 my $target = caller;
49              
50 10         66 strict->import::into($target);
51 10         2826 warnings->import::into($target);
52              
53 10         2877 feature->import::into($target, @FEATURES);
54 10         3719 Feature::Compat::Try->import::into($target);
55 10         3235 builtin::compat->import::into($target, @BUILTINS);
56              
57 10 100       5159 utf8->import::into($target) if $arg{'-utf8'};
58              
59             _import_optional_compat($target, 'Feature::Compat::Class')
60 10 100       593 if $arg{'-class'};
61              
62             _import_optional_compat($target, 'Feature::Compat::Defer')
63 10 100       37 if $arg{'-defer'};
64              
65 10         1449 return;
66             }
67              
68             sub unimport {
69 6     6   87 my ($class, @args) = @_;
70 6         23 _parse_args(@args);
71              
72 5         15 my $target = caller;
73              
74 5         34 strict->unimport::out_of($target);
75 5         1427 warnings->unimport::out_of($target);
76              
77 5         1559 feature->unimport::out_of($target, @FEATURES);
78 5         1431 utf8->unimport::out_of($target);
79              
80 5         1447 return;
81             }
82              
83             sub _parse_args {
84 17     17   42 my @args = @_;
85 17         33 my %arg;
86              
87 17         48 for my $arg (@args) {
88             die __PACKAGE__ . qq{: unknown import option "$arg"\n}
89 11 100       81 unless $KNOWN_ARG{$arg};
90              
91 9         21 $arg{$arg} = 1;
92             }
93              
94 15         66 return %arg;
95             }
96              
97             sub _import_optional_compat {
98 4     4   12 my ($target, $module) = @_;
99              
100 4         21 (my $file = "$module.pm") =~ s{::}{/}g;
101 4         1321 require $file;
102              
103 4         932 $module->import::into($target);
104              
105 4         1257 return;
106             }
107              
108             1;
109              
110             __END__