File Coverage

blib/lib/Module/Faker/Heavy.pm
Criterion Covered Total %
statement 29 29 100.0
branch 7 10 70.0
condition 2 2 100.0
subroutine 6 6 100.0
pod n/a
total 44 47 93.6


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