File Coverage

blib/lib/Module/Faker/Heavy.pm
Criterion Covered Total %
statement 28 28 100.0
branch 7 10 70.0
condition 2 2 100.0
subroutine 6 6 100.0
pod n/a
total 43 46 93.4


line stmt bran cond sub pod time code
1 8     8   160 use v5.20.0;
  8         30  
2 8     8   46 use warnings;
  8         46  
  8         650  
3             package Module::Faker::Heavy 0.027;
4             # ABSTRACT: where the fake sausage gets made
5              
6 8     8   69 use Carp ();
  8         34  
  8         144  
7 8     8   5762 use Text::Template;
  8         34996  
  8         3284  
8              
9             my $template;
10             sub _template {
11 42 100   42   226 return $template if $template;
12              
13 8         18 my $current;
14 8         61 while (my $line = <DATA>) {
15 312         493 chomp $line;
16 312 100       823 if ($line =~ /\A__([^_]+)__\z/) {
17 24         75 my $filename = $1;
18 24 50       159 if ($filename !~ /\A(?:DATA|END)\z/) {
19 24         80 $current = $filename;
20 24         100 next;
21             }
22             }
23              
24 288 50       602 Carp::confess "bogus data section: text outside of file" unless $current;
25              
26 288   100     1281 ($template->{$current} ||= '') .= "$line\n";
27             }
28              
29 8         60 return $template;
30             }
31              
32             sub _render {
33 42     42   135 my ($self, $name, $stash) = @_;
34              
35             Carp::confess "no file template for $name" unless
36 42 50       200 my $template = $self->_template->{ $name };
37              
38             my $text = Text::Template->fill_this_in(
39             $template,
40             DELIMITERS => [ '{{', '}}' ],
41 42         249 HASH => { map {; $_ => \($stash->{$_}) } keys %$stash },
  42         393  
42             );
43              
44 42         16109 return $text;
45             }
46              
47             1;
48              
49             =pod
50              
51             =encoding UTF-8
52              
53             =head1 NAME
54              
55             Module::Faker::Heavy - where the fake sausage gets made
56              
57             =head1 VERSION
58              
59             version 0.027
60              
61             =head1 PERL VERSION
62              
63             This module should work on any version of perl still receiving updates from
64             the Perl 5 Porters. This means it should work on any version of perl
65             released in the last two to three years. (That is, if the most recently
66             released version is v5.40, then this module should work on both v5.40 and
67             v5.38.)
68              
69             Although it may work on older versions of perl, no guarantee is made that the
70             minimum required version will not be increased. The version may be increased
71             for any reason, and there is no promise that patches will be accepted to
72             lower the minimum required perl.
73              
74             =head1 AUTHOR
75              
76             Ricardo Signes <cpan@semiotic.systems>
77              
78             =head1 COPYRIGHT AND LICENSE
79              
80             This software is copyright (c) 2008 by Ricardo Signes.
81              
82             This is free software; you can redistribute it and/or modify it under
83             the same terms as the Perl 5 programming language system itself.
84              
85             =cut
86              
87             __DATA__
88             __META.yml__
89             ---
90             name: {{ $dist->name }}
91             version: {{ $dist->version }}
92             abstract: {{ $dist->abstract }}
93             author:
94             {{ $OUT .= sprintf " - %s\n", $_ for $dist->authors; chomp $OUT; return }}
95             generated_by: Module::Faker version {{ $Module::Faker::VERSION }}
96             license: unknown{{ if (my %requires = $dist->requires) {
97             $OUT .= "\nrequires:";
98             $OUT .= sprintf "\n %s: %s", $_, (defined $requires{$_} ? $requires{$_} : '~') for keys %requires;
99             chomp $OUT;
100             }
101             return;
102             }}
103             meta-spec:
104             url: http://module-build.sourceforge.net/META-spec-v1.3.html
105             version: 1.3
106             __Makefile.PL__
107             use ExtUtils::MakeMaker;
108              
109             WriteMakefile(
110             DISTNAME => "{{ $dist->name }}",
111             NAME => "{{ $dist->_pkgy_name }}",
112             VERSION => "{{ $dist->version }}",
113             ABSTRACT => '{{ my $abs = $dist->abstract; $abs =~ s/'/\'/g; $abs }}',
114             PREREQ_PM => { {{
115             if (my %requires = $dist->_flat_prereqs ) {
116             $OUT .= sprintf "\n '%s' => '%s',", $_,
117             (defined $requires{$_} ? $requires{$_} : 0) for sort keys %requires;
118             }
119             return;
120             }}
121             },
122             );
123             __t/00-nop.t__
124             #!perl
125             use Test::More tests => 1;
126             ok(1);