File: DirStore.pm

package info (click to toggle)
libmodule-starter-plugin-simplestore-perl 0.144-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112 kB
  • sloc: perl: 117; makefile: 2
file content (93 lines) | stat: -rw-r--r-- 2,158 bytes parent folder | download | duplicates (3)
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
85
86
87
88
89
90
91
92
93
use warnings;
use strict;

package Module::Starter::Plugin::DirStore;

our $VERSION = '0.144';

use Carp ();
use File::Basename;

=head1 NAME

Module::Starter::Plugin::DirStore -- module template files in a directory

=head1 VERSION

version 0.144

=head1 SYNOPSIS

 use Module::Starter qw(
   Module::Starter::Simple
   Module::Starter::Plugin::Template
   Module::Starter::Plugin::DirStore
   ...
 );

 Module::Starter->create_distro( ... );

=head1 DESCRIPTION

This Module::Starter plugin is intended to be loaded after
Module::Starter::Plugin::Template.  It implements the C<templates> method,
required by the Template plugin.  The C<DirStore> plugin stores all the
required templates as files in a directory.

=cut

=head1 METHODS

=head2 C<< templates >>

This method reads in the template files and populates the object's C<templates>
attribute.  The module template directory is found by checking the
MODULE_TEMPLATE_DIR environment variable and then the config option
"template_dir".

=cut

sub templates {
    my $self = shift;
    my %template;

    my $template_dir = ($ENV{MODULE_TEMPLATE_DIR} || $self->{template_dir})
        or Carp::croak "template dir not defined";
    Carp::croak "template dir does not exist: $template_dir"
        unless -d $template_dir;

    foreach (glob "$template_dir/*") {
        my $basename = basename $_;
        next if (not -f $_) or ($basename =~ /^\./);
        open my $template_file, '<', $_
          or Carp::croak "couldn't open template: $_";
        $template{$basename} = do {
          local $/ = undef;
          <$template_file>;
        };
    }

    return %template;
}

=head1 AUTHOR

Ricardo SIGNES, C<< <rjbs@cpan.org> >>

=head1 Bugs

Please report any bugs or feature requests to
C<bug-module-starter-plugin-inlinestore@rt.cpan.org>, or through the web
interface at L<http://rt.cpan.org>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 COPYRIGHT

Copyright 2004 Ricardo SIGNES, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1;