File Coverage

blib/lib/Module/Starter/Plugin/InlineStore.pm
Criterion Covered Total %
statement 9 24 37.5
branch 0 6 0.0
condition 0 3 0.0
subroutine 3 5 60.0
pod 1 1 100.0
total 13 39 33.3


line stmt bran cond sub pod time code
1 1     1   3250 use warnings;
  1         1  
  1         24  
2 1     1   4 use strict;
  1         2  
  1         42  
3              
4             package Module::Starter::Plugin::InlineStore;
5              
6             our $VERSION = '0.144';
7              
8 1     1   4 use Carp ();
  1         1  
  1         199  
9              
10             =head1 NAME
11              
12             Module::Starter::Plugin::InlineStore -- inline module template files
13              
14             =head1 VERSION
15              
16             version 0.144
17              
18             =head1 SYNOPSIS
19              
20             use Module::Starter qw(
21             Module::Starter::Simple
22             Module::Starter::Plugin::Template
23             Module::Starter::Plugin::InlineStore
24             ...
25             );
26              
27             Module::Starter->create_distro( ... );
28              
29             =head1 DESCRIPTION
30              
31             This Module::Starter plugin is intended to be loaded after
32             Module::Starter::Plugin::Template. It implements the C method,
33             required by the Template plugin. The C plugin stores all the
34             required templates in a single file, delimited with filenames between
35             triple-underscores. In other words, a very simple template file might look
36             like this:
37              
38             ___Module.pm___
39             package {modulename};
40             1;
41             ___Makefile.PL___
42             die "lousy template"
43              
44             Originally, this module was to use Inline::Files, or at least standard
45             double-underscore indication of file names, but it's just simpler this way.
46             Patches welcome.
47              
48             =cut
49              
50             =head1 METHODS
51              
52             =head2 C<< templates >>
53              
54             This method reads in the template file (described above) and populates the
55             object's C attribute. The module template file is found by checking
56             the MODULE_TEMPLATE_FILE environment variable and then the "template_file"
57             config option.
58              
59             =cut
60              
61             sub _template_filehandle {
62 0     0     my $self = shift;
63              
64 0 0 0       my $template_filename =
65             ($ENV{MODULE_TEMPLATE_FILE} || $self->{template_file})
66             or Carp::croak "no template file defined";
67 0 0         open my $template_file, '<', $template_filename
68             or Carp::croak "couldn't open template file: $template_filename";
69              
70 0           return $template_file;
71             }
72              
73             sub templates {
74 0     0 1   my $self = shift;
75 0           my %template;
76            
77 0           my $template_file = $self->_template_filehandle;
78              
79 0           my $fn = '_';
80 0           while (<$template_file>) {
81 0 0         if (/^___([-_.0-9A-Za-z]+)___$/) {
82 0           $fn = $1;
83 0           $template{$fn} = q{};
84 0           next;
85             }
86 0           $template{$fn} .= $_;
87             }
88              
89 0           return %template;
90             }
91              
92             =head1 AUTHOR
93              
94             Ricardo SIGNES, C<< >>
95              
96             =head1 Bugs
97              
98             Please report any bugs or feature requests to
99             C, or through the web
100             interface at L. I will be notified, and then you'll
101             automatically be notified of progress on your bug as I make changes.
102              
103             =head1 COPYRIGHT
104              
105             Copyright 2004 Ricardo SIGNES, All Rights Reserved.
106              
107             This program is free software; you can redistribute it and/or modify it
108             under the same terms as Perl itself.
109              
110             =cut
111              
112             1;