File: DZil.pm

package info (click to toggle)
libdist-zilla-plugin-checkextratests-perl 0.029-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 260 kB
  • sloc: perl: 598; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 2,048 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use strict;
use warnings;

package Test::DZil;

use Params::Util qw(_HASH0);

use Sub::Exporter -setup => {
    exports => [
        dist_ini   => \'_dist_ini',
        simple_ini => \'_simple_ini',
    ],
    groups => [ default => [qw(dist_ini simple_ini)] ],
};

sub _build_ini_builder {
    my ($starting_core) = @_;
    $starting_core ||= {};

    sub {
        my (@arg) = @_;
        my $new_core = _HASH0( $arg[0] ) ? shift(@arg) : {};

        my $core_config = { %$starting_core, %$new_core };

        my $config = '';

        for my $key ( keys %$core_config ) {
            my @values =
              ref $core_config->{$key}
              ? @{ $core_config->{$key} }
              : $core_config->{$key};

            $config .= "$key = $_\n" for grep { defined } @values;
        }

        $config .= "\n" if length $config;

        for my $line (@arg) {
            my @plugin  = ref $line ? @$line : ( $line, {} );
            my $moniker = shift @plugin;
            my $name    = _HASH0( $plugin[0] ) ? undef : shift @plugin;
            my $payload = shift(@plugin) || {};

            die "TOO MANY ARGS TO PLUGIN GAHLGHALAGH" if @plugin;

            $config .= '[' . $moniker;
            $config .= ' / ' . $name if defined $name;
            $config .= "]\n";

            for my $key ( keys %$payload ) {
                my @values =
                  ref $payload->{$key}
                  ? @{ $payload->{$key} }
                  : $payload->{$key};

                $config .= "$key = $_\n" for @values;
            }

            $config .= "\n";
        }

        return $config;
      }
}

sub _dist_ini {
    _build_ini_builder;
}

sub _simple_ini {
    _build_ini_builder(
        {
            name             => 'DZT-Sample',
            abstract         => 'Sample DZ Dist',
            version          => '0.001',
            author           => 'E. Xavier Ample <example@example.org>',
            license          => 'Perl_5',
            copyright_holder => 'E. Xavier Ample',
        }
    );
}

1;