[Bps-public-commit] template-declare branch, master, updated. 6d2ca7edb02a818992cbb0cd042ae99eff5a30ba
Thomas Sibley
trs at bestpractical.com
Wed Dec 8 10:37:51 EST 2010
The branch, master has been updated
via 6d2ca7edb02a818992cbb0cd042ae99eff5a30ba (commit)
via 1acb6ee6b78368779c583d5826995f0725952291 (commit)
from b6f5efe5d99c2e80daeaf9743eafe9d27c41e784 (commit)
Summary of changes:
Changes | 4 +
META.yml | 3 +-
README | 1366 +++++++++++++++++++++++++++++++------
inc/Module/AutoInstall.pm | 19 +-
inc/Module/Install.pm | 218 ++++---
inc/Module/Install/AutoInstall.pm | 25 +-
inc/Module/Install/Base.pm | 11 +-
inc/Module/Install/Can.pm | 2 +-
inc/Module/Install/Fetch.pm | 2 +-
inc/Module/Install/Include.pm | 2 +-
inc/Module/Install/Makefile.pm | 229 +++++--
inc/Module/Install/Metadata.pm | 267 +++++---
inc/Module/Install/Win32.pm | 2 +-
inc/Module/Install/WriteAll.pm | 7 +-
14 files changed, 1716 insertions(+), 441 deletions(-)
- Log -----------------------------------------------------------------
commit 1acb6ee6b78368779c583d5826995f0725952291
Author: Thomas Sibley <trs at bestpractical.com>
Date: Wed Dec 8 10:37:26 2010 -0500
Update Changes and the README in prep for release
diff --git a/Changes b/Changes
index 454758e..ad22fd7 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,7 @@
+0.44 2010-12-08
+* Added support for $TAG_INDENTATION and $EOL (Marc Chantreux)
+* Add a current_base_path() convenience function (trs)
+
0.43 2009-11-18
* Test warning fixes (Theory)
* Dist fixes suggested by rafl (Sartak)
diff --git a/README b/README
index 202e229..7af3fbf 100644
--- a/README
+++ b/README
@@ -2,283 +2,1196 @@ NAME
Template::Declare - Perlish declarative templates
SYNOPSIS
- "Template::Declare" is a pure-perl declarative HTML/XUL/RDF/XML
+ Here's an example of basic HTML usage:
+
+ package MyApp::Templates;
+ use Template::Declare::Tags; # defaults to 'HTML'
+ use base 'Template::Declare';
+
+ template simple => sub {
+ html {
+ head {}
+ body {
+ p { 'Hello, world wide web!' }
+ }
+ }
+ };
+
+ package main;
+ use Template::Declare;
+ Template::Declare->init( dispatch_to => ['MyApp::Templates'] );
+ print Template::Declare->show( 'simple' );
+
+ And here's the output:
+
+ <html>
+ <head></head>
+ <body>
+ <p>Hello, world wide web!
+ </p>
+ </body>
+ </html>
+
+DESCRIPTION
+ "Template::Declare" is a pure-Perl declarative HTML/XUL/RDF/XML
templating system.
Yes. Another one. There are many others like it, but this one is ours.
A few key features and buzzwords:
- * All templates are 100% pure perl code
+ * All templates are 100% pure Perl code
* Simple declarative syntax
* No angle brackets
- * "Native" XML namespace and declarator support
+ * "Native" XML namespace and declaration support
* Mixins
* Inheritance
+ * Delegation
+
* Public and private templates
+GLOSSARY
+ template class
+ A subclass of Template::Declare in which one or more templates are
+ defined using the "template" keyword, or that inherits templates
+ from a super class.
+
+ template
+ Created with the "template" keyword, a template is a subroutine that
+ uses "tags" to generate output.
+
+ attribute
+ An XML element attribute. For example, in "<img src="foo.png" />",
+ "src" is an attribute of the "img" element.
+
+ tag A subroutine that generates XML element-style output. Tag
+ subroutines execute blocks that generate the output, and can call
+ other tags to generate a properly hierarchical structure.
+
+ tag set
+ A collection of related tags defined in a subclass of
+ Template::Declare::TagSet for a particular purpose, and which can be
+ imported into a template class. For example,
+ Template::Declare::TagSet::HTML defines tags for emitting HTML
+ elements.
+
+ wrapper
+ A subroutine that wraps the output from a template. Useful for
+ wrapping template output in common headers and footers, for example.
+
+ dispatch class
+ A template class that has been passed to "init()" via the
+ "dispatch_to" parameter. When show is called, only templates defined
+ in or mixed into the dispatch classes will be executed.
+
+ path
+ The name specified for a template when it is created by the
+ "template" keyword, or when a template is mixed into a template
+ class.
+
+ mixin
+ A template mixed into a template class via "mix". Mixed-in templates
+ may be mixed in under prefix paths to distinguish them from the
+ templates defined in the dispatch classes.
+
+ alias
+ A template aliased into a template class via "alias". Aliased
+ templates may be added under prefix paths to distinguish them from
+ the templates defined in the dispatch classes.
+
+ package variable
+ Variables defined when mixing templates into a template class. These
+ variables are available only to the mixed-in templates; they are not
+ even accessible from the template class in which the templates were
+ defined.
+
+ helper
+ A subroutine used in templates to assist in the generation of
+ output, or in template classes to assist in the mixing-in of
+ templates. Output helpers include "outs()" for rending text output
+ and "xml_decl()" for rendering XML declarations. Mixin helpers
+ include "into" for specifying a template class to mix into, and
+ "under" for specifying a path prefix under which to mix templates.
+
USAGE
- Basic usage
- ##############################
- # Basic HTML usage:
- ###############################
+ Like other Perl templating systems, there are two parts to
+ Template::Declare: the templates and the code that loads and executes
+ the templates. Unlike other template systems, the templates are written
+ in Perl classes. A simple HTML example is in the "SYNOPSIS".
+
+ A slightly more advanced example
+ In this example, we'll show off how to set attributes on HTML tags, how
+ to call other templates, and how to declare a *private* template that
+ can't be called directly. We'll also show passing arguments to
+ templates. First, the template class:
+
package MyApp::Templates;
- use Template::Declare::Tags; # defaults to 'HTML'
use base 'Template::Declare';
+ use Template::Declare::Tags;
+
+ private template 'util/header' => sub {
+ head {
+ title { 'This is a webpage' };
+ meta {
+ attr { generator => "This is not your father's frontpage" }
+ }
+ }
+ };
+
+ private template 'util/footer' => sub {
+ my $self = shift;
+ my $time = shift || gmtime;
+
+ div {
+ attr { id => "footer"};
+ "Page last generated at $time."
+ }
+ };
template simple => sub {
+ my $self = shift;
+ my $user = shift || 'world wide web';
+
html {
- head {}
+ show('util/header');
body {
- p {'Hello, world wide web!'}
- }
+ img { src is 'hello.jpg' }
+ p {
+ attr { class => 'greeting'};
+ "Hello, $user!"
+ };
+ };
+ show('util/footer', 'noon');
}
};
+ A few notes on this example:
+
+ * Since no parameter was passed to "use Template::Declare::Tags", the
+ HTML tags are imported by default.
+
+ * The "private" keyword indicates that a template is private. That
+ means that it can only be executed by other templates within the
+ template class in which it's declared. By default,
+ "Template::Declare->show" will not dispatch to it.
+
+ * The two private templates have longer paths than we've seen before:
+ "util/header" and "util/footer". They must of course be called by
+ their full path names. You can put any characters you like into
+ template names, but the use of Unix filesystem-style paths is the
+ most common (following on the example of HTML::Mason).
+
+ * The first argument to a template is a class name. This can be useful
+ for calling methods defined in the class.
+
+ * The "show" sub executes another template. In this example, the
+ "simple" template calls "show('util/header')" and
+ "show('util/footer')" in order to execute those private templates in
+ the appropriate places.
+
+ * Additional arguments to "show" are passed on to the template being
+ executed. here, "show('util/footer', 'noon')" is passing "noon" to
+ the "util/footer" template, with the result that the "last generated
+ at" string will display "noon" instead of the default "gmtime".
+
+ * In the same way, note that the "simple" template expects an
+ additional argument, a user name.
+
+ * In addition to using "attr" to declare attributes for an element,
+ you can use "is", as in
+
+ img { src is 'hello.jpg' }
+
+ Now for executing the template:
+
package main;
use Template::Declare;
- Template::Declare->init( roots => ['MyApp::Templates']);
- print Template::Declare->show( 'simple');
-
- # Output:
- #
- #
- # <html>
- # <head></head>
- # <body>
- # <p>Hello, world wide web!
- # </p>
- # </body>
- # </html>
-
- ###############################
- # Let's do XUL!
- ###############################
+ Template::Declare->init( dispatch_to => ['MyApp::Templates'] );
+ print Template::Declare->show( '/simple', 'TD user');
+
+ We've told Template::Declare to dispatch to templates defined in our
+ template class. And note how an additional argument is passed to
+ "show()"; that argument, "TD user", will be passed to the "simple"
+ template, where it will be used in the $user variable.
+
+ The output looks like this:
+
+ <html>
+ <head>
+ <title>This is a webpage</title>
+ <meta generator="This is not your father's frontpage" />
+ </head>
+ <body>
+ <img src="hello.jpg" />
+ <p class="greeting">Hello, TD user!</p>
+ </body>
+ <div id="footer">Page last generated at Thu Sep 3 20:56:14 2009.</div>
+ </html>
+
+ Note that the single quote in "father's" was quoted for you. We sanitize
+ your output for you to help prevent cross-site scripting attacks.
+
+ XUL
+ Template::Declare isn't limited to just HTML. Let's do XUL!
+
package MyApp::Templates;
use base 'Template::Declare';
use Template::Declare::Tags 'XUL';
template main => sub {
xml_decl { 'xml', version => '1.0' };
- xml_decl { 'xml-stylesheet', href => "chrome://global/skin/", type => "text/css" };
+ xml_decl {
+ 'xml-stylesheet',
+ href => "chrome://global/skin/",
+ type => "text/css"
+ };
groupbox {
caption { attr { label => 'Colors' } }
radiogroup {
- for my $id ( qw< orange violet yellow > ) {
- radio {
- attr {
- id => $id,
- label => ucfirst($id),
- $id eq 'violet' ?
- (selected => 'true') : ()
+ for my $id ( qw< orange violet yellow > ) {
+ radio {
+ attr {
+ id => $id,
+ label => ucfirst($id),
+ $id eq 'violet' ? (selected => 'true') : ()
+ }
}
- }
- } # for
+ } # for
}
}
};
+ The first thing to do in a template class is to subclass
+ Template::Declare itself. This is required so that Template::Declare
+ always knows that it's dealing with templates. The second thing is to
+ "use Template::Declare::Tags" to import the set of tag subroutines you
+ need to generate the output you want. In this case, we've imported tags
+ to support the creation of XUL. Other tag sets include HTML (the
+ default), and RDF.
+
+ Templates are created using the "template" keyword:
+
+ template main => sub { ... };
+
+ The first argument is the name of the template, also known as its
+ *path*. In this case, the template's path is "main" (or "/main", both
+ are allowed (to keep both PHP and HTML::Mason fans happy). The second
+ argument is an anonymous subroutine that uses the tag subs (and any
+ other necessary code) to generate the output for the template.
+
+ The tag subs imported into your class take blocks as arguments, while a
+ number of helper subs take other arguments. For example, the "xml_decl"
+ helper takes as its first argument the name of the XML declaration to be
+ output, and then a hash of the attributes of that declaration:
+
+ xml_decl { 'xml', version => '1.0' };
+
+ Tag subs are used by simply passing a block to them that generates the
+ output. Said block may of course execute other tag subs in order to
+ represent the hierarchy required in your output. Here, the "radiogroup"
+ tag calls the "radio" tag for each of three different colors:
+
+ radiogroup {
+ for my $id ( qw< orange violet yellow > ) {
+ radio {
+ attr {
+ id => $id,
+ label => ucfirst($id),
+ $id eq 'violet' ? (selected => 'true') : ()
+ }
+ }
+ } # for
+ }
+
+ Note the "attr" sub. This helper function is used to add attributes to
+ the element created by the tag in which they appear. In the previous
+ example, the the "id", "label", and "selected" attributes are added to
+ each "radio" output.
+
+ Once you've written your templates, you'll want to execute them. You do
+ so by telling Template::Declare what template classes to dispatch to and
+ then asking it to show you the output from a template:
+
+ package main;
+ Template::Declare->init( dispatch_to => ['MyApp::Templates'] );
+ print Template::Declare->show( 'main' );
+
+ The path passed to "show" can be either "main" or </main>, as you
+ prefer. In either event, the output would look like this:
+
+ <?xml version="1.0"?>
+ <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+ <groupbox>
+ <caption label="Colors" />
+ <radiogroup>
+ <radio id="orange" label="Orange" />
+ <radio id="violet" label="Violet" selected="true" />
+ <radio id="yellow" label="Yellow" />
+ </radiogroup>
+ </groupbox>
+
+ Postprocessing
+ Sometimes you just want simple syntax for inline elements. The following
+ shows how to use a postprocessor to emphasize text _like this_.
+
+ package MyApp::Templates;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+
+ template before => sub {
+ h1 {
+ outs "Welcome to ";
+ em { "my" };
+ outs " site. It's ";
+ em { "great" };
+ outs "!";
+ };
+ };
+
+ template after => sub {
+ h1 { "Welcome to _my_ site. It's _great_!" };
+ h2 { outs_raw "This is _not_ emphasized." };
+ img { src is '/foo/_bar_baz.png' };
+ };
+
+ Here we've defined two templates in our template class, with the paths
+ "before" and "after". The one new thing to note is the use of the "outs"
+ and "outs_raw" subs. "outs" XML-encodes its argument and outputs it. You
+ can also just specify a string to be output within a tag call, but if
+ you need to mix tags and plain text within a tag call, as in the
+ "before" template here, you'll need to use "outs" to get things to
+ output as you would expect. "outs_raw" is the same, except that it does
+ no XML encoding.
+
+ Now let's have a look at how we use these templates with a
+ post-processor:
+
package main;
- Template::Declare->init( roots => ['MyApp::Templates']);
- print Template::Declare->show('main')
-
- # Output:
- #
- # <?xml version="1.0"?>
- # <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
- #
- # <groupbox>
- # <caption label="Colors" />
- # <radiogroup>
- # <radio id="orange" label="Orange" />
- # <radio id="violet" label="Violet" selected="true" />
- # <radio id="yellow" label="Yellow" />
- # </radiogroup>
- # </groupbox>
+ use Template::Declare;
+ Template::Declare->init(
+ dispatch_to => ['MyApp::Templates'],
+ postprocessor => \&emphasize,
+ strict => 1,
+ );
+
+ print Template::Declare->show( 'before' );
+ print Template::Declare->show( 'after' );
+
+ sub emphasize {
+ my $text = shift;
+ $text =~ s{_(.+?)_}{<em>$1</em>}g;
+ return $text;
+ }
+
+ As usual, we've told Template::Declare to dispatch to our template
+ class. A new parameter to "init()" is "postprocessor", which is a code
+ reference that should expect the template output as an argument. It can
+ then transform that text however it sees fit before returning it for
+ final output. In this example, the "emphasize" subroutine looks for text
+ that's emphasized using _underscores_ and turns them into
+ "<em>emphasis</em>" HTML elements.
+
+ We then execute both the "before" and the "after" templates with the
+ output ending up as:
+
+ <h1>Welcome to
+ <em>my</em> site. It's
+ <em>great</em>!</h1>
+ <h1>Welcome to <em>my</em> site. It's <em>great</em>!</h1>
+ <h2>This is _not_ emphasized.</h2>
+ <img src="/foo/_bar_baz.png" />
+
+ The thing to note here is that text passed to "outs_raw" is not passed
+ through the postprocessor, and neither are attribute values (like the
+ "img"'s "src").
- A slightly more advanced example
- In this example, we'll show off how to set attributes on HTML tags, how
- to call other templates and how to declare a *private* template that
- can't be called directly. We'll also show passing arguments to
- templates.
+ Inheritance
+ Templates are really just methods. You can subclass your template
+ packages to override some of those methods:
- package MyApp::Templates;
- use Template::Declare::Tags;
- use base 'Template::Declare';
+ package MyApp::Templates::GenericItem;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
- private template 'header' => sub {
- head {
- title { 'This is a webpage'};
- meta { attr { generator => "This is not your father's frontpage"}}
+ template 'list' => sub {
+ my ($self, @items) = @_;
+ div {
+ show('item', $_) for @items;
}
- };
+ };
+ template 'item' => sub {
+ my ($self, $item) = @_;
+ span { $item }
+ };
+
+ package MyApp::Templates::BlogPost;
+ use Template::Declare::Tags;
+ use base 'MyApp::Templates::GenericItem';
+
+ template 'item' => sub {
+ my ($self, $post) = @_;
+ h1 { $post->title }
+ div { $post->body }
+ };
+
+ Here we have two template classes; the second,
+ "MyApp::Templates::BlogPost", inherits from the first,
+ "MyApp::Templates::GeniricItem". Note also that
+ "MyApp::Templates::BlogPost" overrides the "item" template. So execute
+ these templates:
+
+ package main;
+ use Template::Declare;
+
+ Template::Declare->init( dispatch_to => ['MyApp::Templates::GenericItem'] );
+ print Template::Declare->show( 'list', 'foo', 'bar', 'baz' );
+
+ Template::Declare->init( dispatch_to => ['MyApp::Templates::BlogPost'] );
+ my $post = My::Post->new(title => 'Hello', body => 'first post');
+ print Template::Declare->show( 'item', $post );
+
+ First we execute the "list" template in the base class, passing in some
+ items, and then we re-"init()" Template::Declare and execute *its*
+ "list" template with an appropriate argument. Here's the output:
+
+ <div>
+ <span>foo</span>
+ <span>bar</span>
+ <span>baz</span>
+ </div>
+
+ <h1>Hello</h1>
+ <div>first post</div>
+
+ So the override of the "list" template in the subclass works as
+ expected. For another example, see Jifty::View::Declare::CRUD.
+
+ Wrappers
+ There are two levels of wrappers in Template::Declare: template wrappers
+ and smart tag wrappers.
+
+ Template Wrappers
+ "create_wrapper" declares a wrapper subroutine that can be called like a
+ tag sub, but can optionally take arguments to be passed to the wrapper
+ sub. For example, if you wanted to wrap all of the output of a template
+ in the usual HTML headers and footers, you can do something like this:
+
+ package MyApp::Templates;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+
+ BEGIN {
+ create_wrapper wrap => sub {
+ my $code = shift;
+ my %params = @_;
+ html {
+ head { title { outs "Hello, $params{user}!"} };
+ body {
+ $code->();
+ div { outs 'This is the end, my friend' };
+ };
+ }
+ };
+ }
+
+ template inner => sub {
+ wrap {
+ h1 { outs "Hello, Jesse, s'up?" };
+ } user => 'Jesse';
+ };
+
+ Note how the "wrap" wrapper function is available for calling after it
+ has been declared in a "BEGIN" block. Also note how you can pass
+ arguments to the function after the closing brace (you don't need a
+ comma there!).
+
+ The output from the "inner" template will look something like this:
+
+ <html>
+ <head>
+ <title>Hello, Jesse!</title>
+ </head>
+ <body>
+ <h1>Hello, Jesse, s'up?</h1>
+ <div>This is the end, my friend</div>
+ </body>
+ </html>
+
+ Tag Wrappers
+ Tag wrappers are similar to template wrappers, but mainly function as
+ syntax sugar for creating subroutines that behave just like tags but are
+ allowed to contain arbitrary Perl code and to dispatch to other tag. To
+ create one, simply create a named subroutine with the prototype "(&)" so
+ that its interface is the same as tags. Within it, use
+ "smart_tag_wrapper" to do the actual execution, like so:
+
+ package My::Template;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+
+ sub myform (&) {
+ my $code = shift;
+
+ smart_tag_wrapper {
+ my %params = @_; # set using 'with'
+ form {
+ attr { %{ $params{attr} } };
+ $code->();
+ input { attr { type => 'submit', value => $params{value} } };
+ };
+ };
+ }
+
+ template edit_prefs => sub {
+ with(
+ attr => { id => 'edit_prefs', action => 'edit.html' },
+ value => 'Save'
+ ), myform {
+ label { 'Time Zone' };
+ input { type is 'text'; name is 'tz' };
+ };
+ };
- private template 'footer' => sub {
+ Note in the "edit_prefs" template that we've used "with" to set up
+ parameters to be passed to the smart wrapper. "smart_tag_wrapper()" is
+ the device that allows you to receive those parameters, and also handles
+ the magic of making sure that the tags you execute within it are
+ properly output. Here we've used "myform" similarly to "form", only
+ "myform" does something different with the "with()" arguments and
+ outputs a submit element.
+
+ Executing this template:
+
+ Template::Declare->init( dispatch_to => ['My::Template'] );
+ print Template::Declare->show('edit_prefs');
+
+ Yields this output:
+
+ <form action="edit.html" id="edit_prefs">
+ <label>Time Zone</label>
+ <input type="text" name="tz" />
+ <input type="submit" value="Save" />
+ </form>
+
+ Class Search Dispatching
+ The classes passed via the "dispatch_to" parameter to "init()" specify
+ all of the templates that can be executed by subsequent calls to
+ "show()". Template searches through these classes in order to find those
+ templates. Thus it can be useful, when you're creating your template
+ classes and determining which to use for particular class to "show()",
+ to have templates that override other templates. This is similar to how
+ an operating system will search all the paths in the $PATH environment
+ variable for a program to run, and to HTML::Mason component roots or
+ Template::Toolkit's "INCLUDE_PATH" parameter.
+
+ For example, say you have this template class that defines a template
+ that you'll use for displaying images on your Web site.
+
+ package MyApp::UI::Standard;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+
+ template image => sub {
+ my ($self, $src, $title) = @_;
+ img {
+ src is $src;
+ title is $title;
+ };
+ };
+
+ As usual, you can use it like so:
+
+ my @template_classes = 'MyApp::UI::Standard';
+ Template::Declare->init( dispatch_to => \@template_classes );
+ print Template::Declare->show('image', 'foo.png', 'Foo');
+
+ We're explicitly using a reference to @template_classes so that we can
+ manage this list ourselves.
+
+ The output of this will be:
+
+ <div class="std">
+ <img src="foo.png" title="Foo" />
+ <p class="caption"></p>
+ </div>
+
+ But say that in some sections of your site you need to have a more
+ formal treatment of your photos. Maybe you publish photos from a wire
+ service and need to provide an appropriate credit. You might write the
+ template class like so:
+
+ package MyApp::UI::Formal;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+
+ template image => sub {
+ my ($self, $src, $title, $credit, $caption) = @_;
+ div {
+ class is 'formal';
+ img {
+ src is $src;
+ title is $title;
+ };
+ p {
+ class is 'credit';
+ outs "Photo by $credit";
+ };
+ p {
+ class is 'caption';
+ outs $caption;
+ };
+ };
+ };
+
+ This, too, will work as expected, but the useful bit that comes in when
+ you're mixing and matching template classes to pass to "dispatch_to"
+ before rendering a page. Maybe you always pass have MyApp::UI::Standard
+ to "dispatch_to" because it has all of your standard formatting
+ templates. But when the code realizes that a particular page needs the
+ more formal treatment, you can prepend the formal class to the list:
+
+ unshift @template_classes, 'MyApp::UI::Formal';
+ print Template::Declare->show(
+ 'image',
+ 'ap.png',
+ 'AP Photo',
+ 'Clark Kent',
+ 'Big news'
+ );
+ shift @template_classes;
+
+ In this way, made the formal "image" template will be found first,
+ yielding this output:
+
+ <div class="formal">
+ <img src="ap.png" title="AP Photo" />
+ <p class="credit">Photo by Clark Kent</p>
+ <p class="caption">Big news</p>
+ </div>
+
+ At the end, we've shifted the formal template class off the
+ "dispatch_to" list in order to restore the template classes the default
+ configuration, ready for the next request.
+
+ Template Composition
+ There are two methods of template composition: mixins and delegation.
+ Their interfaces are very similar, the only difference being the
+ template invocant.
+
+ Mixins
+ Let's start with a mixin.
+
+ package MyApp::UtilTemplates;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+
+ template content => sub {
+ my $self = shift;
+ my @paras = @_;
+ h1 { $self->get_title };
+ div {
+ id is 'content';
+ p { $_ } for @paras;
+ };
+ };
+
+ package MyApp::Templates;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+ mix MyApp::UtilTemplates under '/util';
+
+ sub get_title { 'Kashmir' }
+
+ template story => sub {
my $self = shift;
- my $time = shift || gmtime;
-
- div { attr { id => "footer"};
- "Page last generated at $time."
+ html {
+ head {
+ title { "My Site: " . $self->get_title };
+ };
+ body {
+ show( 'util/content' => 'first paragraph', 'second paragraph' );
+ };
+ };
+ };
+
+ The first template class, "MyApp::UtilTemplates", defines a utility
+ template, called "content", for outputting the contents of page. Note
+ its call to "$self->get_title" even though it doesn't have a "get_title"
+ method. This is part of the mixin's "contract": it requires that the
+ class it's mixed into have a "get_title()" method.
+
+ The second template class, "MyApp::Templates", mixes
+ "MyApp::UtilTemplates" into itself under the path "/util" and defines a
+ "get_title()" method as required by the mixin. Then, its "story"
+ template calls the mixed-in template as "util/content", because the
+ "content" template was mixed into the current template under "/util".
+ Get it?
+
+ Now we can use the usual template invocation:
+
+ package main;
+ Template::Declare->init( dispatch_to => ['MyApp::Templates'] );
+ print Template::Declare->show('story');
+
+ To appreciate our output:
+
+ <html>
+ <head>
+ <title>My Site: Kashmir</title>
+ </head>
+ <body>
+ <h1>Kashmir</h1>
+ <div id="content">
+ <p>fist paragraph</p>
+ <p>second paragraph</p>
+ </div>
+ </body>
+ </html>
+
+ Mixins are a very useful tool for template authors to add reusable
+ functionality to their template classes. But it's important to pay
+ attention to the mixin contracts so that you're sure to implement the
+ required API in your template class (here, the "get_title()" method).
+
+ Aliases
+ Aliases are very similar to mixins, but implement delegation as a
+ composition pattern, rather than mixins. The upshot is that there is no
+ contract provided by an aliased class: it just works. This is because
+ the invocant is the class from which the aliases are imported, and
+ therefore it will dispatch to methods defined in the aliased class.
+
+ For example, say that you wanted to output a sidebar on pages that need
+ one (perhaps your CMS has sidebar things). We can define a template
+ class that has a template for that:
+
+ package MyApp::UI::Stuff;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+
+ sub img_path { '/ui/css' }
+
+ template sidebar => sub {
+ my ($self, $thing) = @_;
+ div {
+ class is 'sidebar';
+ img { src is $self->img_path . '/sidebar.png' };
+ p { $_->content } for $thing->get_things;
+ };
+ };
+
+ Note the use of the "img_path()" method defined in the template class
+ and used by the "sidebar" template. Now let's use it:
+
+ package MyApp::Render;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+ alias MyApp::UI::Stuff under '/stuff';
+
+ template page => sub {
+ my ($self, $page) = @_;
+ h1 { $page->title };
+ for my $thing ($page->get_things) {
+ if ($thing->is('paragraph')) {
+ p { $thing->content };
+ } elsif ($thing->is('sidebar')) {
+ show( '/stuff/sidebar' => $thing );
+ }
}
- };
+ };
- template simple => sub {
- my $self = shift;
- my $user = shift || 'world wide web';
+ Here our rendering template class has aliased "MyApp::UI::Stuff" under
+ "/stuff". So the "page" template calls "show('/stuff/sidebar')" to
+ invoke the sidebar template. If we run this:
- html {
- show('header');
- body {
- p { attr { class => 'greeting'};
- "Hello, $user!"};
- };
- show('footer');
+ Template::Declare->init( dispatch_to => ['MyApp::Render'] );
+ print Template::Declare->show( page => $page );
+
+ We get output as you might expect:
+
+ <h1>My page title</h1>
+ <p>Page paragraph</p>
+ <div class="sidebar">
+ <img src="/ui/css/sidebar.png" />
+ <p>Sidebar paragraph</p>
+ <p>Another paragraph</p>
+ </div>
+
+ Now, let's say that you have political stuff that you want to use a
+ different image for in the sidebar. If that's the only difference, we
+ can subclass "MyApp::UI::Stuff" and just override the "img_path()"
+ method:
+
+ package MyApp::UI::Stuff::Politics;
+ use Template::Declare::Tags;
+ use base 'MyApp::UI::Stuff';
+
+ sub img_path { '/politics/ui/css' }
+
+ Now let's mix that into a politics template class:
+
+ package MyApp::Render::Politics;
+ use Template::Declare::Tags;
+ use base 'Template::Declare';
+ alias MyApp::UI::Stuff::Politics under '/politics';
+
+ template page => sub {
+ my ($self, $page) = @_;
+ h1 { $page->title };
+ for my $thing ($page->get_things) {
+ if ($thing->is('paragraph')) {
+ p { $thing->content };
+ } elsif ($thing->is('sidebar')) {
+ show( '/politics/sidebar' => $thing );
+ }
}
- };
-
- package main;
- use Template::Declare;
- Template::Declare->init( roots => ['MyApp::Templates']);
- print Template::Declare->show( 'simple', 'TD user');
-
- # Output:
- #
- # <html>
- # <head>
- # <title>This is a webpage
- # </title>
- # <meta generator="This is not your father's frontpage" />
- # </head>
- # <body>
- # <p class="greeting">Hello, TD user!
- # </p>
- # </body>
- # <div id="footer">Page last generated at Mon Jul 2 17:09:34 2007.</div>
- # </html>
-
- For more options, especially the "native" XML namespace support and more
- samples, see Template::Declare::Tags.
+ };
- Postprocessing
- Sometimes you just want simple syntax for inline elements. The following
- shows how to use a postprocessor to emphasize text _like this_.
+ The only difference between this template class and "MyApp::Render" is
+ that it aliases "MyApp::UI::Stuff::Politics" under "/politics", and then
+ calls "show('/politics/sidebar')" in the "page" template. Running this
+ template:
+
+ Template::Declare->init( dispatch_to => ['MyApp::Render::Politics'] );
+ print Template::Declare->show( page => $page );
+
+ Yields output using the value of the subclass's "img_path()" method --
+ that is, the sidebar image is now /politics/ui/css/sidebar.png instead
+ of /ui/css/sidebar.png:
+
+ <h1>My page title</h1>
+ <p>Page paragraph</p>
+ <div class="sidebar">
+ <img src="/politics/ui/css/sidebar.png" />
+ <p>Sidebar paragraph</p>
+ <p>Another paragraph</p>
+ </div>
+
+ Other Tricks
+ The delegation behavior of "alias" actually makes it a decent choice for
+ template authors to mix and match libraries of template classes as
+ appropriate, without worrying about side effects. You can even alias
+ templates in one template class into another template class if you're
+ not the author of that class by using the "into" keyword:
+
+ alias My::UI::Widgets into Your::UI::View under '/widgets';
+
+ Now the templates defined in "Your::UI::View" are available in
+ "My::UI::Widgets" under "/widgets". The "mix" method supports this
+ syntax as well, though it's not necessarily recommended, given that you
+ would not be able to fulfill any contracts unless you re-opened the
+ class into which you mixed the templates. But in any case, authors of
+ framework view classes might find this functionality useful for
+ automatically aliasing template classes into a single dispatch template
+ class.
+
+ Another trick is to alias or mix your templates with package variables
+ specific to the composition. Do so via the "setting" keyword:
+
+ package My::Templates;
+ mix Some::Mixin under '/mymix', setting { name => 'Larry' };
+
+ The templates mixed from "Some::Mixin" into "My::Templates" have package
+ variables set for them that are accessible *only* from their mixed-in
+ paths. For example, if this template was defined in "Some::Mixin":
+
+ template howdy => sub {
+ my $self = shift;
+ outs "Howdy, " . $self->package_variable('name') || 'Jesse';
+ };
+
+ Then "show('mymix/howdy')" called on "My::Templates" will output "Howdy,
+ Larry", while the output from "show('howdy')" will output "Howdy,
+ Jesse". In other words, package variables defined for the mixed-in
+ templates are available only to the mixins and not to the original. The
+ same functionality exists for "alias" as well.
+
+ Indentation configuration
+ by default, Template::Declare renders a readable xml adding end of lines
+ and a one column indentation. This behavior could break a webpage design
+ or add a significant amount of chars to your xml output. This could be
+ changed by overwritting the default values. so
+
+ $Template::Declare::Tags::TAG_INDENTATION = 0;
+ $Template::Declare::Tags::EOL = "";
+ say Template::Declare->show('main');
+
+ will render
+
+ <html><body><p>hi</p></body></html>
- package MyApp::Templates;
- use Template::Declare::Tags;
- use base 'Template::Declare';
-
- template before => sub {
- h1 {
- outs "Welcome to ";
- em { "my"};
- outs " site. It's ";
- em { "great"};
- outs "!";
- };
- };
-
- template after => sub {
- h1 { "Welcome to _my_ site. It's _great_!"};
- h2 { outs_raw "This is _not_ emphasized."};
- };
-
- package main;
- use Template::Declare;
- Template::Declare->init( roots => ['MyApp::Templates'], postprocessor => \&emphasize);
- print Template::Declare->show( 'before');
- print Template::Declare->show( 'after');
-
- sub emphasize {
- my $text = shift;
- $text =~ s{_(.+?)_}{<em>$1</em>}g;
- return $text;
- }
-
- # Output:
- #
- # <h1>Welcome to
- # <em>my</em> site. It's
- # <em>great</em>!</h1>
- # <h1>Welcome to <em>my</em> site. It's <em>great</em>!</h1>
- # <h2>This is _not_ emphasized.</h2>
-
- Multiple template roots (search paths)
- Inheritance
- Aliasing
METHODS
init
This *class method* initializes the "Template::Declare" system.
+ dispatch_to
+ An array reference of classes to search for templates.
+ Template::Declare will search this list of classes in order to find
+ a template path.
+
roots
+ Deprecated. Just like "dispatch_to", only the classes are searched
+ in reverse order. Maintained for backward compatibility and for the
+ pleasure of those who want to continue using Template::Declare the
+ way that Jesse's "crack-addled brain" intended.
+
postprocessor
+ A coderef called to postprocess the HTML or XML output of your
+ templates. This is to alleviate using Tags for simple text markup.
+
+ around_template
+ A coderef called instead of rendering each template. The coderef
+ will receive three arguments: a coderef to invoke to render the
+ template, the template's path, an arrayref of the arguments to the
+ template, and the coderef of the template itself. You can use this
+ for instrumentation. For example:
+
+ Template::Declare->init(around_template => sub {
+ my ($orig, $path, $args, $code) = @_;
+ my $start = time;
+ $orig->();
+ warn "Rendering $path took " . (time - $start) . " seconds.";
+ });
+
+ strict
+ Die in exceptional situations, such as when a template can't be
+ found, rather than just warn. False by default for backward
+ compatibility. The default may be changed in the future, so
+ specifying the value explicitly is recommended.
show TEMPLATE_NAME
+ Template::Declare->show( 'howdy', name => 'Larry' );
+ my $output = Template::Declare->show('index');
+
Call "show" with a "template_name" and "Template::Declare" will render
- that template. Content generated by show can be accessed with the
- "output" method if the output method you've chosen returns content
- instead of outputting it directly.
+ that template. Subsequent arguments will be passed to the template.
+ Content generated by "show()" can be accessed via the "output()" method
+ if the output method you've chosen returns content instead of outputting
+ it directly.
+
+ If called in scalar context, this method will also just return the
+ content when available.
+
+ Template Composition
+ Sometimes you want to mix templates from one class into another class,
+ or delegate template execution to a class of templates. "alias()" and
+ "mix()" are your keys to doing so.
+
+ mix
+ mix Some::Clever::Mixin under '/mixin';
+ mix Some::Other::Mixin under '/otmix', setting { name => 'Larry' };
+ mix My::Mixin into My::View, under '/mymix';
+
+ Mixes templates from one template class into another class. When the
+ mixed-in template is called, its invocant will be the class into which
+ it was mixed. This type of composition is known as a "mixin" in
+ object-oriented parlance. See Template Composition for extended examples
+ and a comparison to "alias".
+
+ The first parameter is the name of the template class to be mixed in.
+ The "under" keyword tells "mix" where to put the templates. For example,
+ a "foo" template in "Some::Clever::Mixin" will be mixed in as
+ "mymixin/foo".
+
+ The "setting" keyword specifies package variables available only to the
+ mixed-in copies of templates. These are available to the templates as
+ "$self->package_variable($varname)".
+
+ The "into" keyword tells "mix" into what class to mix the templates.
+ Without this keyword, "mix" will mix them into the calling class.
+
+ For those who prefer a direct OO syntax for mixins, just call "mix()" as
+ a method on the class to be mixed in. To replicate the above three
+ examples without the use of the sugar:
+
+ Some::Clever::Mixin->mix( '/mixin' );
+ Some::Other::Mixin->mix( '/otmix', { name => 'Larry' } );
+ My::Mixin->mix( 'My::View', '/mymix' );
+
+ alias
+ alias Some::Clever:Templates under '/delegate';
+ alias Some::Other::Templates under '/send_to', { name => 'Larry' };
+ alias UI::Stuff into My::View, under '/mystuff';
+
+ Aliases templates from one template class into another class. When an
+ alias called, its invocant will be the class from which it was aliased.
+ This type of composition is known as "delegation" in object-oriented
+ parlance. See Template Composition for extended examples and a
+ comparison to "mix".
+
+ The first parameter is the name of the template class to alias. The
+ "under" keyword tells "alias" where to put the templates. For example, a
+ "foo" template in "Some::Clever::Templates" will be aliased as
+ "delegate/foo".
+
+ The "setting" keyword specifies package variables available only to the
+ aliases. These are available to the templates as
+ "$self->package_variable($varname)".
+
+ The "into" keyword tells "alias" into what class to alias the templates.
+ Without this keyword, "alias" will alias them into the calling class.
+
+ For those who prefer a direct OO syntax for mixins, just call "alias()"
+ as a method on the class to be mixed in. To replicate the above three
+ examples without the use of the sugar:
+
+ Some::Clever:Templates->alias( '/delegate' );
+ Some::Other::Templates->alias( '/send_to', { name => 'Larry' } );
+ UI::Stuff->alias( 'My::View', '/mystuff' );
+
+ package_variable( VARIABLE )
+ $td->package_variable( $varname => $value );
+ $value = $td->package_variable( $varname );
+
+ Returns a value set for a mixed-in template's variable, if any were
+ specified when the template was mixed-in. See "mix" for details.
+
+ package_variables( VARIABLE )
+ $td->package_variables( $variables );
+ $variables = $td->package_variables;
+
+ Get or set a hash reference of variables for a mixed-in template. See
+ "mix" for details.
+
+ Templates registration and lookup
+ resolve_template TEMPLATE_PATH INCLUDE_PRIVATE_TEMPLATES
+ my $code = Template::Declare->resolve_template($template);
+ my $code = Template::Declare->has_template($template, 1);
+
+ Turns a template path ("TEMPLATE_PATH") into a "CODEREF". If the boolean
+ "INCLUDE_PRIVATE_TEMPLATES" is true, resolves private template in
+ addition to public ones. "has_template()" is an alias for this method.
- (If called in scalar context, this method will also just return the
- content when available).
+ First it looks through all the valid Template::Declare classes defined
+ via "dispatch_to". For each class, it looks to see if it has a template
+ called $template_name directly (or via a mixin).
- alias
- alias Some::Clever::Mixin under '/mixin';
+ has_template TEMPLATE_PATH INCLUDE_PRIVATE_TEMPLATES
+ An alias for "resolve_template".
- import_templates
- import_templates Wifty::UI::something under '/something';
+ register_template( TEMPLATE_NAME, CODEREF )
+ MyApp::Templates->register_template( howdy => sub { ... } );
- path_for $template
- Returns the path for the template name to be used for show, adjusted
- with paths used in import_templates.
+ This method registers a template called "TEMPLATE_NAME" in the calling
+ class. As you might guess, "CODEREF" defines the template's
+ implementation. This method is mainly intended to be used internally, as
+ you use the "template" keyword to create templates, right?
- has_template PACKAGE TEMPLATE_NAME SHOW_PRIVATE
- Takes a package, template name and a boolean. The boolean determines
- whether to show private templates.
+ register_private_template( TEMPLATE_NAME, CODEREF )
+ MyApp::Templates->register_private_template( howdy => sub { ... } );
- Returns a reference to the template's code if found. Otherwise, returns
- undef.
+ This method registers a private template called "TEMPLATE_NAME" in the
+ calling class. As you might guess, "CODEREF" defines the template's
+ implementation.
- This method is an alias for "resolve_template"
+ Private templates can't be called directly from user code but only from
+ other templates.
- resolve_template TEMPLATE_PATH INCLUDE_PRIVATE_TEMPLATES
- Turns a template path ("TEMPLATE_PATH") into a "CODEREF". If the boolean
- "INCLUDE_PRIVATE_TEMPLATES" is true, resolves private template in
- addition to public ones.
+ This method is mainly intended to be used internally, as you use the
+ "private template" expression to create templates, right?
- First it looks through all the valid Template::Declare roots. For each
- root, it looks to see if the root has a template called $template_name
- directly (or via an "import" statement). Then it looks to see if there
- are any "alias"ed paths for the root with prefixes that match the
- template we're looking for.
+ buffer
+ Gets or sets the String::BufferStack object; this is a class method.
- register_template PACKAGE TEMPLATE_NAME CODEREF
- This method registers a template called "TEMPLATE_NAME" in package
- "PACKAGE". As you might guess, "CODEREF" defines the template's
- implementation.
+ You can use it to manipulate the output from tags as they are output.
+ It's used internally to make the tags nest correctly, and be output to
+ the right place. We're not sure if there's ever a need for you to frob
+ it by hand, but it does enable things like the following:
- register_template PACKAGE TEMPLATE_NAME CODEREF
- This method registers a private template called "TEMPLATE_NAME" in
- package "PACKAGE". As you might guess, "CODEREF" defines the template's
- implementation.
+ template simple => sub {
+ html {
+ head {}
+ body {
+ Template::Declare->buffer->set_filter( sub {uc shift} );
+ p { 'Whee!' }
+ p { 'Hello, world wide web!' }
+ Template::Declare->buffer->clear_top if rand() < 0.5;
+ }
+ }
+ };
- Private templates can't be called directly from user code but only from
- other templates.
+ ...which outputs, with equal regularity, either:
+
+ <html>
+ <head></head>
+ <body>
+ <P>WHEE!</P>
+ <P>HELLO, WORLD WIDE WEB!</P>
+ </body>
+ </html>
+
+ ...or:
+
+ <html>
+ <head></head>
+ <body></body>
+ </html>
+
+ We'll leave it to you to judge whether or not that's actually useful.
+
+ Helpers
+ You don't need to call any of this directly.
+
+ into
+ $class = into $class;
+
+ "into" is a helper method providing semantic sugar for the "mix" method.
+ All it does is return the name of the class on which it was called.
+
+ Old, deprecated or just better to avoid
+ import_templates
+ import_templates MyApp::Templates under '/something';
+
+ Like "mix()", but without support for the "into" or "setting" keywords.
+ That is, it mixes templates into the calling template class and does not
+ support package variables for those mixins.
+
+ Deprecated in favor of "mix". Will be supported for a long time, but new
+ code should use "mix()".
+
+ new_buffer_frame
+ $td->new_buffer_frame;
+ # same as
+ $td->buffer->push( private => 1 );
+
+ Creates a new buffer frame, using "push" in String::BufferStack with
+ "private".
+
+ Deprecated in favor of dealing with "buffer" directly.
+
+ end_buffer_frame
+ my $buf = $td->end_buffer_frame;
+ # same as
+ my $buf = $td->buffer->pop;
+
+ Deletes and returns the topmost buffer, using "pop" in
+ String::BufferStack.
+
+ Deprecated in favor of dealing with "buffer" directly.
+
+ path_for $template
+ my $path = Template::Declare->path_for('index');
+
+ Returns the path for the template name to be used for show, adjusted
+ with paths used in "mix". Note that this will only work for the last
+ class into which you imported the template. This method is, therefore,
+ deprecated.
PITFALLS
- We're reusing the perl interpreter for our templating langauge, but Perl
+ We're reusing the perl interpreter for our templating language, but Perl
was not designed specifically for our purpose here. Here are some known
pitfalls while you're scripting your templates with this module.
* It's quite common to see tag sub calling statements without trailing
semi-colons right after "}". For instance,
- template foo => {
+ template foo => sub {
p {
a { attr { src => '1.png' } }
a { attr { src => '2.png' } }
@@ -288,7 +1201,7 @@ PITFALLS
is equivalent to
- template foo => {
+ template foo => sub {
p {
a { attr { src => '1.png' } };
a { attr { src => '2.png' } };
@@ -297,7 +1210,8 @@ PITFALLS
};
But "xml_decl" is a notable exception. Please always put a trailing
- semicolon after "xml_decl { ... }", or you'll mess up the outputs.
+ semicolon after "xml_decl { ... }", or you'll mess up the order of
+ output.
* Another place that requires trailing semicolon is the statements
before a Perl looping statement, an if statement, or a "show" call.
@@ -305,7 +1219,7 @@ PITFALLS
p { "My links:" };
for (@links) {
- with( src => $_ ), a {}
+ with ( src => $_ ), a {}
}
The ";" after " p { ... } " is required here, or Perl will complain
@@ -316,6 +1230,13 @@ PITFALLS
h1 { 'heading' }; # this trailing semicolon is mandatory
show 'tag_tag'
+ * The "is" syntax for declaring tag attributes also requires a
+ trailing semicolon, unless it is the only statement in a block. For
+ example,
+
+ p { class is 'item'; id is 'item1'; outs "This is an item" }
+ img { src is 'cat.gif' }
+
* Literal strings that have tag siblings won't be captured. So the
following template
@@ -323,30 +1244,52 @@ PITFALLS
produces
- <p>
- <em>world</em>
- </p>
+ <p>
+ <em>world</em>
+ </p>
instead of the desired output
- <p>
- hello
- <em>world</em>
- </p>
+ <p>
+ hello
+ <em>world</em>
+ </p>
You can use "outs" here to solve this problem:
p { outs 'hello'; em { 'world' } }
- Note you can always get rid of the "outs" crap if the string literal
- is the only element of the containing block:
+ Note you can always get rid of "outs" if the string literal is the
+ only element of the containing block:
+
+ p { 'hello, world!' }
+
+ * Look out! If the if block is the last block/statement and the
+ condition part is evaluated to be 0:
+
+ p { if ( 0 ) { } }
+
+ produces
+
+ <p>0</p>
+
+ instead of the more intuitive output:
+
+ <p></p>
- p { 'hello, world!' }
+ This is because "if ( 0 )" is the last expression, so 0 is returned
+ as the value of the whole block, which is used as the content of <p>
+ tag.
+
+ To get rid of this, just put an empty string at the end so it
+ returns empty string as the content instead of 0:
+
+ p { if ( 0 ) { } '' }
BUGS
Crawling all over, baby. Be very, very careful. This code is so cutting
edge, it can only be fashioned from carbon nanotubes. But we're already
- using this thing in production :) Make sure you have read the PITFALL
+ using this thing in production :) Make sure you have read the "PITFALLS"
section above :)
Some specific bugs and design flaws that we'd love to see fixed.
@@ -357,12 +1300,17 @@ BUGS
"bug-template-declare at rt.cpan.org".
SEE ALSO
- Template::Declare::Tags, Template::Declare::TagSet,
- Template::Declare::TagSet::HTML, Template::Declare::TagSet::XUL, Jifty.
+ Template::Declare::Tags
+ Template::Declare::TagSet
+ Template::Declare::TagSet::HTML
+ Template::Declare::TagSet::XUL
+ Jifty
AUTHOR
Jesse Vincent <jesse at bestpractical.com>
-COPYRIGHT
- Copyright 2006-2009 Best Practical Solutions, LLC
+LICENSE
+ Template::Declare is Copyright 2006-2009 Best Practical Solutions, LLC.
+
+ Template::Declare is distributed under the same terms as Perl itself.
commit 6d2ca7edb02a818992cbb0cd042ae99eff5a30ba
Author: Thomas Sibley <trs at bestpractical.com>
Date: Wed Dec 8 10:37:40 2010 -0500
Update install toolchain
diff --git a/META.yml b/META.yml
index 5a92d80..33171c4 100644
--- a/META.yml
+++ b/META.yml
@@ -9,7 +9,7 @@ build_requires:
configure_requires:
ExtUtils::MakeMaker: 6.42
distribution_type: module
-generated_by: 'Module::Install version 0.91'
+generated_by: 'Module::Install version 1.00'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -23,6 +23,7 @@ requires:
Class::Accessor::Fast: 0
Class::Data::Inheritable: 0
Class::ISA: 0
+ HTML::Lint: 0
String::BufferStack: 1.1
perl: 5.8.2
resources:
diff --git a/inc/Module/AutoInstall.pm b/inc/Module/AutoInstall.pm
index dfb8ef7..60b90ea 100644
--- a/inc/Module/AutoInstall.pm
+++ b/inc/Module/AutoInstall.pm
@@ -253,6 +253,8 @@ sub import {
# import to main::
no strict 'refs';
*{'main::WriteMakefile'} = \&Write if caller(0) eq 'main';
+
+ return (@Existing, @Missing);
}
sub _running_under {
@@ -672,7 +674,20 @@ sub _load {
sub _load_cpan {
return if $CPAN::VERSION and $CPAN::Config and not @_;
require CPAN;
- if ( $CPAN::HandleConfig::VERSION ) {
+
+ # CPAN-1.82+ adds CPAN::Config::AUTOLOAD to redirect to
+ # CPAN::HandleConfig->load. CPAN reports that the redirection
+ # is deprecated in a warning printed at the user.
+
+ # CPAN-1.81 expects CPAN::HandleConfig->load, does not have
+ # $CPAN::HandleConfig::VERSION but cannot handle
+ # CPAN::Config->load
+
+ # Which "versions expect CPAN::Config->load?
+
+ if ( $CPAN::HandleConfig::VERSION
+ || CPAN::HandleConfig->can('load')
+ ) {
# Newer versions of CPAN have a HandleConfig module
CPAN::HandleConfig->load;
} else {
@@ -802,4 +817,4 @@ END_MAKE
__END__
-#line 1056
+#line 1071
diff --git a/inc/Module/Install.pm b/inc/Module/Install.pm
index 51eda5d..8ee839d 100644
--- a/inc/Module/Install.pm
+++ b/inc/Module/Install.pm
@@ -19,6 +19,9 @@ package Module::Install;
use 5.005;
use strict 'vars';
+use Cwd ();
+use File::Find ();
+use File::Path ();
use vars qw{$VERSION $MAIN};
BEGIN {
@@ -28,7 +31,7 @@ BEGIN {
# This is not enforced yet, but will be some time in the next few
# releases once we can make sure it won't clash with custom
# Module::Install extensions.
- $VERSION = '0.91';
+ $VERSION = '1.00';
# Storage for the pseudo-singleton
$MAIN = undef;
@@ -38,18 +41,25 @@ BEGIN {
}
+sub import {
+ my $class = shift;
+ my $self = $class->new(@_);
+ my $who = $self->_caller;
-
-
-
-# Whether or not inc::Module::Install is actually loaded, the
-# $INC{inc/Module/Install.pm} is what will still get set as long as
-# the caller loaded module this in the documented manner.
-# If not set, the caller may NOT have loaded the bundled version, and thus
-# they may not have a MI version that works with the Makefile.PL. This would
-# result in false errors or unexpected behaviour. And we don't want that.
-my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
-unless ( $INC{$file} ) { die <<"END_DIE" }
+ #-------------------------------------------------------------
+ # all of the following checks should be included in import(),
+ # to allow "eval 'require Module::Install; 1' to test
+ # installation of Module::Install. (RT #51267)
+ #-------------------------------------------------------------
+
+ # Whether or not inc::Module::Install is actually loaded, the
+ # $INC{inc/Module/Install.pm} is what will still get set as long as
+ # the caller loaded module this in the documented manner.
+ # If not set, the caller may NOT have loaded the bundled version, and thus
+ # they may not have a MI version that works with the Makefile.PL. This would
+ # result in false errors or unexpected behaviour. And we don't want that.
+ my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
+ unless ( $INC{$file} ) { die <<"END_DIE" }
Please invoke ${\__PACKAGE__} with:
@@ -61,26 +71,28 @@ not:
END_DIE
-
-
-
-
-# If the script that is loading Module::Install is from the future,
-# then make will detect this and cause it to re-run over and over
-# again. This is bad. Rather than taking action to touch it (which
-# is unreliable on some platforms and requires write permissions)
-# for now we should catch this and refuse to run.
-if ( -f $0 ) {
- my $s = (stat($0))[9];
-
- # If the modification time is only slightly in the future,
- # sleep briefly to remove the problem.
- my $a = $s - time;
- if ( $a > 0 and $a < 5 ) { sleep 5 }
-
- # Too far in the future, throw an error.
- my $t = time;
- if ( $s > $t ) { die <<"END_DIE" }
+ # This reportedly fixes a rare Win32 UTC file time issue, but
+ # as this is a non-cross-platform XS module not in the core,
+ # we shouldn't really depend on it. See RT #24194 for detail.
+ # (Also, this module only supports Perl 5.6 and above).
+ eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006;
+
+ # If the script that is loading Module::Install is from the future,
+ # then make will detect this and cause it to re-run over and over
+ # again. This is bad. Rather than taking action to touch it (which
+ # is unreliable on some platforms and requires write permissions)
+ # for now we should catch this and refuse to run.
+ if ( -f $0 ) {
+ my $s = (stat($0))[9];
+
+ # If the modification time is only slightly in the future,
+ # sleep briefly to remove the problem.
+ my $a = $s - time;
+ if ( $a > 0 and $a < 5 ) { sleep 5 }
+
+ # Too far in the future, throw an error.
+ my $t = time;
+ if ( $s > $t ) { die <<"END_DIE" }
Your installer $0 has a modification time in the future ($s > $t).
@@ -89,15 +101,12 @@ This is known to create infinite loops in make.
Please correct this, then run $0 again.
END_DIE
-}
-
-
-
+ }
-# Build.PL was formerly supported, but no longer is due to excessive
-# difficulty in implementing every single feature twice.
-if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" }
+ # Build.PL was formerly supported, but no longer is due to excessive
+ # difficulty in implementing every single feature twice.
+ if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" }
Module::Install no longer supports Build.PL.
@@ -107,23 +116,42 @@ Please remove all Build.PL files and only use the Makefile.PL installer.
END_DIE
+ #-------------------------------------------------------------
+ # To save some more typing in Module::Install installers, every...
+ # use inc::Module::Install
+ # ...also acts as an implicit use strict.
+ $^H |= strict::bits(qw(refs subs vars));
+ #-------------------------------------------------------------
+ unless ( -f $self->{file} ) {
+ foreach my $key (keys %INC) {
+ delete $INC{$key} if $key =~ /Module\/Install/;
+ }
-# To save some more typing in Module::Install installers, every...
-# use inc::Module::Install
-# ...also acts as an implicit use strict.
-$^H |= strict::bits(qw(refs subs vars));
-
+ local $^W;
+ require "$self->{path}/$self->{dispatch}.pm";
+ File::Path::mkpath("$self->{prefix}/$self->{author}");
+ $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self );
+ $self->{admin}->init;
+ @_ = ($class, _self => $self);
+ goto &{"$self->{name}::import"};
+ }
+ local $^W;
+ *{"${who}::AUTOLOAD"} = $self->autoload;
+ $self->preload;
+ # Unregister loader and worker packages so subdirs can use them again
+ delete $INC{'inc/Module/Install.pm'};
+ delete $INC{'Module/Install.pm'};
+ # Save to the singleton
+ $MAIN = $self;
-use Cwd ();
-use File::Find ();
-use File::Path ();
-use FindBin;
+ return 1;
+}
sub autoload {
my $self = shift;
@@ -136,7 +164,21 @@ sub autoload {
# Delegate back to parent dirs
goto &$code unless $cwd eq $pwd;
}
- $$sym =~ /([^:]+)$/ or die "Cannot autoload $who - $sym";
+ unless ($$sym =~ s/([^:]+)$//) {
+ # XXX: it looks like we can't retrieve the missing function
+ # via $$sym (usually $main::AUTOLOAD) in this case.
+ # I'm still wondering if we should slurp Makefile.PL to
+ # get some context or not ...
+ my ($package, $file, $line) = caller;
+ die <<"EOT";
+Unknown function is found at $file line $line.
+Execution of $file aborted due to runtime errors.
+
+If you're a contributor to a project, you may need to install
+some Module::Install extensions from CPAN (or other repository).
+If you're a user of a module, please contact the author.
+EOT
+ }
my $method = $1;
if ( uc($method) eq $method ) {
# Do nothing
@@ -152,33 +194,6 @@ sub autoload {
};
}
-sub import {
- my $class = shift;
- my $self = $class->new(@_);
- my $who = $self->_caller;
-
- unless ( -f $self->{file} ) {
- require "$self->{path}/$self->{dispatch}.pm";
- File::Path::mkpath("$self->{prefix}/$self->{author}");
- $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self );
- $self->{admin}->init;
- @_ = ($class, _self => $self);
- goto &{"$self->{name}::import"};
- }
-
- *{"${who}::AUTOLOAD"} = $self->autoload;
- $self->preload;
-
- # Unregister loader and worker packages so subdirs can use them again
- delete $INC{"$self->{file}"};
- delete $INC{"$self->{path}.pm"};
-
- # Save to the singleton
- $MAIN = $self;
-
- return 1;
-}
-
sub preload {
my $self = shift;
unless ( $self->{extensions} ) {
@@ -204,6 +219,7 @@ sub preload {
my $who = $self->_caller;
foreach my $name ( sort keys %seen ) {
+ local $^W;
*{"${who}::$name"} = sub {
${"${who}::AUTOLOAD"} = "${who}::$name";
goto &{"${who}::AUTOLOAD"};
@@ -214,12 +230,18 @@ sub preload {
sub new {
my ($class, %args) = @_;
+ delete $INC{'FindBin.pm'};
+ {
+ # to suppress the redefine warning
+ local $SIG{__WARN__} = sub {};
+ require FindBin;
+ }
+
# ignore the prefix on extension modules built from top level.
my $base_path = Cwd::abs_path($FindBin::Bin);
unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) {
delete $args{prefix};
}
-
return $args{_self} if $args{_self};
$args{dispatch} ||= 'Admin';
@@ -272,8 +294,10 @@ END_DIE
sub load_extensions {
my ($self, $path, $top) = @_;
+ my $should_reload = 0;
unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) {
unshift @INC, $self->{prefix};
+ $should_reload = 1;
}
foreach my $rv ( $self->find_extensions($path) ) {
@@ -281,12 +305,13 @@ sub load_extensions {
next if $self->{pathnames}{$pkg};
local $@;
- my $new = eval { require $file; $pkg->can('new') };
+ my $new = eval { local $^W; require $file; $pkg->can('new') };
unless ( $new ) {
warn $@ if $@;
next;
}
- $self->{pathnames}{$pkg} = delete $INC{$file};
+ $self->{pathnames}{$pkg} =
+ $should_reload ? delete $INC{$file} : $INC{$file};
push @{$self->{extensions}}, &{$new}($pkg, _top => $top );
}
@@ -348,17 +373,24 @@ sub _caller {
return $call;
}
+# Done in evals to avoid confusing Perl::MinimumVersion
+eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@;
sub _read {
local *FH;
- if ( $] >= 5.006 ) {
- open( FH, '<', $_[0] ) or die "open($_[0]): $!";
- } else {
- open( FH, "< $_[0]" ) or die "open($_[0]): $!";
- }
+ open( FH, '<', $_[0] ) or die "open($_[0]): $!";
+ my $string = do { local $/; <FH> };
+ close FH or die "close($_[0]): $!";
+ return $string;
+}
+END_NEW
+sub _read {
+ local *FH;
+ open( FH, "< $_[0]" ) or die "open($_[0]): $!";
my $string = do { local $/; <FH> };
close FH or die "close($_[0]): $!";
return $string;
}
+END_OLD
sub _readperl {
my $string = Module::Install::_read($_[0]);
@@ -379,18 +411,26 @@ sub _readpod {
return $string;
}
+# Done in evals to avoid confusing Perl::MinimumVersion
+eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@;
sub _write {
local *FH;
- if ( $] >= 5.006 ) {
- open( FH, '>', $_[0] ) or die "open($_[0]): $!";
- } else {
- open( FH, "> $_[0]" ) or die "open($_[0]): $!";
+ open( FH, '>', $_[0] ) or die "open($_[0]): $!";
+ foreach ( 1 .. $#_ ) {
+ print FH $_[$_] or die "print($_[0]): $!";
}
+ close FH or die "close($_[0]): $!";
+}
+END_NEW
+sub _write {
+ local *FH;
+ open( FH, "> $_[0]" ) or die "open($_[0]): $!";
foreach ( 1 .. $#_ ) {
print FH $_[$_] or die "print($_[0]): $!";
}
close FH or die "close($_[0]): $!";
}
+END_OLD
# _version is for processing module versions (eg, 1.03_05) not
# Perl versions (eg, 5.8.1).
@@ -427,4 +467,4 @@ sub _CLASS ($) {
1;
-# Copyright 2008 - 2009 Adam Kennedy.
+# Copyright 2008 - 2010 Adam Kennedy.
diff --git a/inc/Module/Install/AutoInstall.pm b/inc/Module/Install/AutoInstall.pm
index 58dd026..f1f5356 100644
--- a/inc/Module/Install/AutoInstall.pm
+++ b/inc/Module/Install/AutoInstall.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.91';
+ $VERSION = '1.00';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
@@ -37,12 +37,33 @@ sub auto_install {
$self->include('Module::AutoInstall');
require Module::AutoInstall;
- Module::AutoInstall->import(
+ my @features_require = Module::AutoInstall->import(
(@config ? (-config => \@config) : ()),
(@core ? (-core => \@core) : ()),
$self->features,
);
+ my %seen;
+ my @requires = map @$_, map @$_, grep ref, $self->requires;
+ while (my ($mod, $ver) = splice(@requires, 0, 2)) {
+ $seen{$mod}{$ver}++;
+ }
+ my @build_requires = map @$_, map @$_, grep ref, $self->build_requires;
+ while (my ($mod, $ver) = splice(@build_requires, 0, 2)) {
+ $seen{$mod}{$ver}++;
+ }
+ my @configure_requires = map @$_, map @$_, grep ref, $self->configure_requires;
+ while (my ($mod, $ver) = splice(@configure_requires, 0, 2)) {
+ $seen{$mod}{$ver}++;
+ }
+
+ my @deduped;
+ while (my ($mod, $ver) = splice(@features_require, 0, 2)) {
+ push @deduped, $mod => $ver unless $seen{$mod}{$ver}++;
+ }
+
+ $self->requires(@deduped);
+
$self->makemaker_args( Module::AutoInstall::_make_args() );
my $class = ref($self);
diff --git a/inc/Module/Install/Base.pm b/inc/Module/Install/Base.pm
index 60a74d2..b55bda3 100644
--- a/inc/Module/Install/Base.pm
+++ b/inc/Module/Install/Base.pm
@@ -4,7 +4,7 @@ package Module::Install::Base;
use strict 'vars';
use vars qw{$VERSION};
BEGIN {
- $VERSION = '0.91';
+ $VERSION = '1.00';
}
# Suspend handler for "redefined" warnings
@@ -51,13 +51,18 @@ sub admin {
#line 106
sub is_admin {
- $_[0]->admin->VERSION;
+ ! $_[0]->admin->isa('Module::Install::Base::FakeAdmin');
}
sub DESTROY {}
package Module::Install::Base::FakeAdmin;
+use vars qw{$VERSION};
+BEGIN {
+ $VERSION = $Module::Install::Base::VERSION;
+}
+
my $fake;
sub new {
@@ -75,4 +80,4 @@ BEGIN {
1;
-#line 154
+#line 159
diff --git a/inc/Module/Install/Can.pm b/inc/Module/Install/Can.pm
index e65e4f6..71ccc27 100644
--- a/inc/Module/Install/Can.pm
+++ b/inc/Module/Install/Can.pm
@@ -9,7 +9,7 @@ use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.91';
+ $VERSION = '1.00';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff --git a/inc/Module/Install/Fetch.pm b/inc/Module/Install/Fetch.pm
index 05f2079..ec1f106 100644
--- a/inc/Module/Install/Fetch.pm
+++ b/inc/Module/Install/Fetch.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.91';
+ $VERSION = '1.00';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff --git a/inc/Module/Install/Include.pm b/inc/Module/Install/Include.pm
index 7e792e0..a28cd4c 100644
--- a/inc/Module/Install/Include.pm
+++ b/inc/Module/Install/Include.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.91';
+ $VERSION = '1.00';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff --git a/inc/Module/Install/Makefile.pm b/inc/Module/Install/Makefile.pm
index 98779db..5dfd0e9 100644
--- a/inc/Module/Install/Makefile.pm
+++ b/inc/Module/Install/Makefile.pm
@@ -4,10 +4,11 @@ package Module::Install::Makefile;
use strict 'vars';
use ExtUtils::MakeMaker ();
use Module::Install::Base ();
+use Fcntl qw/:flock :seek/;
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.91';
+ $VERSION = '1.00';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
@@ -25,8 +26,8 @@ sub prompt {
die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])";
}
- # In automated testing, always use defaults
- if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) {
+ # In automated testing or non-interactive session, always use defaults
+ if ( ($ENV{AUTOMATED_TESTING} or -! -t STDIN) and ! $ENV{PERL_MM_USE_DEFAULT} ) {
local $ENV{PERL_MM_USE_DEFAULT} = 1;
goto &ExtUtils::MakeMaker::prompt;
} else {
@@ -34,21 +35,112 @@ sub prompt {
}
}
+# Store a cleaned up version of the MakeMaker version,
+# since we need to behave differently in a variety of
+# ways based on the MM version.
+my $makemaker = eval $ExtUtils::MakeMaker::VERSION;
+
+# If we are passed a param, do a "newer than" comparison.
+# Otherwise, just return the MakeMaker version.
+sub makemaker {
+ ( @_ < 2 or $makemaker >= eval($_[1]) ) ? $makemaker : 0
+}
+
+# Ripped from ExtUtils::MakeMaker 6.56, and slightly modified
+# as we only need to know here whether the attribute is an array
+# or a hash or something else (which may or may not be appendable).
+my %makemaker_argtype = (
+ C => 'ARRAY',
+ CONFIG => 'ARRAY',
+# CONFIGURE => 'CODE', # ignore
+ DIR => 'ARRAY',
+ DL_FUNCS => 'HASH',
+ DL_VARS => 'ARRAY',
+ EXCLUDE_EXT => 'ARRAY',
+ EXE_FILES => 'ARRAY',
+ FUNCLIST => 'ARRAY',
+ H => 'ARRAY',
+ IMPORTS => 'HASH',
+ INCLUDE_EXT => 'ARRAY',
+ LIBS => 'ARRAY', # ignore ''
+ MAN1PODS => 'HASH',
+ MAN3PODS => 'HASH',
+ META_ADD => 'HASH',
+ META_MERGE => 'HASH',
+ PL_FILES => 'HASH',
+ PM => 'HASH',
+ PMLIBDIRS => 'ARRAY',
+ PMLIBPARENTDIRS => 'ARRAY',
+ PREREQ_PM => 'HASH',
+ CONFIGURE_REQUIRES => 'HASH',
+ SKIP => 'ARRAY',
+ TYPEMAPS => 'ARRAY',
+ XS => 'HASH',
+# VERSION => ['version',''], # ignore
+# _KEEP_AFTER_FLUSH => '',
+
+ clean => 'HASH',
+ depend => 'HASH',
+ dist => 'HASH',
+ dynamic_lib=> 'HASH',
+ linkext => 'HASH',
+ macro => 'HASH',
+ postamble => 'HASH',
+ realclean => 'HASH',
+ test => 'HASH',
+ tool_autosplit => 'HASH',
+
+ # special cases where you can use makemaker_append
+ CCFLAGS => 'APPENDABLE',
+ DEFINE => 'APPENDABLE',
+ INC => 'APPENDABLE',
+ LDDLFLAGS => 'APPENDABLE',
+ LDFROM => 'APPENDABLE',
+);
+
sub makemaker_args {
- my $self = shift;
+ my ($self, %new_args) = @_;
my $args = ( $self->{makemaker_args} ||= {} );
- %$args = ( %$args, @_ );
+ foreach my $key (keys %new_args) {
+ if ($makemaker_argtype{$key}) {
+ if ($makemaker_argtype{$key} eq 'ARRAY') {
+ $args->{$key} = [] unless defined $args->{$key};
+ unless (ref $args->{$key} eq 'ARRAY') {
+ $args->{$key} = [$args->{$key}]
+ }
+ push @{$args->{$key}},
+ ref $new_args{$key} eq 'ARRAY'
+ ? @{$new_args{$key}}
+ : $new_args{$key};
+ }
+ elsif ($makemaker_argtype{$key} eq 'HASH') {
+ $args->{$key} = {} unless defined $args->{$key};
+ foreach my $skey (keys %{ $new_args{$key} }) {
+ $args->{$key}{$skey} = $new_args{$key}{$skey};
+ }
+ }
+ elsif ($makemaker_argtype{$key} eq 'APPENDABLE') {
+ $self->makemaker_append($key => $new_args{$key});
+ }
+ }
+ else {
+ if (defined $args->{$key}) {
+ warn qq{MakeMaker attribute "$key" is overriden; use "makemaker_append" to append values\n};
+ }
+ $args->{$key} = $new_args{$key};
+ }
+ }
return $args;
}
# For mm args that take multiple space-seperated args,
# append an argument to the current list.
sub makemaker_append {
- my $self = sShift;
+ my $self = shift;
my $name = shift;
my $args = $self->makemaker_args;
- $args->{name} = defined $args->{$name}
- ? join( ' ', $args->{name}, @_ )
+ $args->{$name} = defined $args->{$name}
+ ? join( ' ', $args->{$name}, @_ )
: join( ' ', @_ );
}
@@ -89,25 +181,22 @@ sub inc {
$self->makemaker_args( INC => shift );
}
-my %test_dir = ();
-
sub _wanted_t {
- /\.t$/ and -f $_ and $test_dir{$File::Find::dir} = 1;
}
sub tests_recursive {
my $self = shift;
- if ( $self->tests ) {
- die "tests_recursive will not work if tests are already defined";
- }
my $dir = shift || 't';
unless ( -d $dir ) {
die "tests_recursive dir '$dir' does not exist";
}
- %test_dir = ();
+ my %tests = map { $_ => 1 } split / /, ($self->tests || '');
require File::Find;
- File::Find::find( \&_wanted_t, $dir );
- $self->tests( join ' ', map { "$_/*.t" } sort keys %test_dir );
+ File::Find::find(
+ sub { /\.t$/ and -f $_ and $tests{"$File::Find::dir/*.t"} = 1 },
+ $dir
+ );
+ $self->tests( join ' ', sort keys %tests );
}
sub write {
@@ -130,12 +219,13 @@ sub write {
# an underscore, even though its own version may contain one!
# Hence the funny regexp to get rid of it. See RT #35800
# for details.
- $self->build_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );
- $self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );
+ my $v = $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/;
+ $self->build_requires( 'ExtUtils::MakeMaker' => $v );
+ $self->configure_requires( 'ExtUtils::MakeMaker' => $v );
} else {
# Allow legacy-compatibility with 5.005 by depending on the
# most recent EU:MM that supported 5.005.
- $self->build_requires( 'ExtUtils::MakeMaker' => 6.42 );
+ $self->build_requires( 'ExtUtils::MakeMaker' => 6.42 );
$self->configure_requires( 'ExtUtils::MakeMaker' => 6.42 );
}
@@ -143,59 +233,115 @@ sub write {
my $args = $self->makemaker_args;
$args->{DISTNAME} = $self->name;
$args->{NAME} = $self->module_name || $self->name;
- $args->{VERSION} = $self->version;
$args->{NAME} =~ s/-/::/g;
+ $args->{VERSION} = $self->version or die <<'EOT';
+ERROR: Can't determine distribution version. Please specify it
+explicitly via 'version' in Makefile.PL, or set a valid $VERSION
+in a module, and provide its file path via 'version_from' (or
+'all_from' if you prefer) in Makefile.PL.
+EOT
+
+ $DB::single = 1;
if ( $self->tests ) {
- $args->{test} = { TESTS => $self->tests };
+ my @tests = split ' ', $self->tests;
+ my %seen;
+ $args->{test} = {
+ TESTS => (join ' ', grep {!$seen{$_}++} @tests),
+ };
+ } elsif ( $Module::Install::ExtraTests::use_extratests ) {
+ # Module::Install::ExtraTests doesn't set $self->tests and does its own tests via harness.
+ # So, just ignore our xt tests here.
+ } elsif ( -d 'xt' and ($Module::Install::AUTHOR or $ENV{RELEASE_TESTING}) ) {
+ $args->{test} = {
+ TESTS => join( ' ', map { "$_/*.t" } grep { -d $_ } qw{ t xt } ),
+ };
}
if ( $] >= 5.005 ) {
$args->{ABSTRACT} = $self->abstract;
- $args->{AUTHOR} = $self->author;
+ $args->{AUTHOR} = join ', ', @{$self->author || []};
}
- if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) {
- $args->{NO_META} = 1;
+ if ( $self->makemaker(6.10) ) {
+ $args->{NO_META} = 1;
+ #$args->{NO_MYMETA} = 1;
}
- if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) {
+ if ( $self->makemaker(6.17) and $self->sign ) {
$args->{SIGN} = 1;
}
unless ( $self->is_admin ) {
delete $args->{SIGN};
}
+ if ( $self->makemaker(6.31) and $self->license ) {
+ $args->{LICENSE} = $self->license;
+ }
- # Merge both kinds of requires into prereq_pm
my $prereq = ($args->{PREREQ_PM} ||= {});
%$prereq = ( %$prereq,
- map { @$_ }
+ map { @$_ } # flatten [module => version]
map { @$_ }
grep $_,
- ($self->configure_requires, $self->build_requires, $self->requires)
+ ($self->requires)
);
# Remove any reference to perl, PREREQ_PM doesn't support it
delete $args->{PREREQ_PM}->{perl};
- # merge both kinds of requires into prereq_pm
- my $subdirs = ($args->{DIR} ||= []);
+ # Merge both kinds of requires into BUILD_REQUIRES
+ my $build_prereq = ($args->{BUILD_REQUIRES} ||= {});
+ %$build_prereq = ( %$build_prereq,
+ map { @$_ } # flatten [module => version]
+ map { @$_ }
+ grep $_,
+ ($self->configure_requires, $self->build_requires)
+ );
+
+ # Remove any reference to perl, BUILD_REQUIRES doesn't support it
+ delete $args->{BUILD_REQUIRES}->{perl};
+
+ # Delete bundled dists from prereq_pm, add it to Makefile DIR
+ my $subdirs = ($args->{DIR} || []);
if ($self->bundles) {
+ my %processed;
foreach my $bundle (@{ $self->bundles }) {
- my ($file, $dir) = @$bundle;
- push @$subdirs, $dir if -d $dir;
- delete $prereq->{$file};
+ my ($mod_name, $dist_dir) = @$bundle;
+ delete $prereq->{$mod_name};
+ $dist_dir = File::Basename::basename($dist_dir); # dir for building this module
+ if (not exists $processed{$dist_dir}) {
+ if (-d $dist_dir) {
+ # List as sub-directory to be processed by make
+ push @$subdirs, $dist_dir;
+ }
+ # Else do nothing: the module is already present on the system
+ $processed{$dist_dir} = undef;
+ }
}
}
+ unless ( $self->makemaker('6.55_03') ) {
+ %$prereq = (%$prereq,%$build_prereq);
+ delete $args->{BUILD_REQUIRES};
+ }
+
if ( my $perl_version = $self->perl_version ) {
eval "use $perl_version; 1"
or die "ERROR: perl: Version $] is installed, "
. "but we need version >= $perl_version";
+
+ if ( $self->makemaker(6.48) ) {
+ $args->{MIN_PERL_VERSION} = $perl_version;
+ }
}
- $args->{INSTALLDIRS} = $self->installdirs;
+ if ($self->installdirs) {
+ warn qq{old INSTALLDIRS (probably set by makemaker_args) is overriden by installdirs\n} if $args->{INSTALLDIRS};
+ $args->{INSTALLDIRS} = $self->installdirs;
+ }
- my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args;
+ my %args = map {
+ ( $_ => $args->{$_} ) } grep {defined($args->{$_} )
+ } keys %$args;
my $user_preop = delete $args{dist}->{PREOP};
- if (my $preop = $self->admin->preop($user_preop)) {
+ if ( my $preop = $self->admin->preop($user_preop) ) {
foreach my $key ( keys %$preop ) {
$args{dist}->{$key} = $preop->{$key};
}
@@ -219,9 +365,9 @@ sub fix_up_makefile {
. ($self->postamble || '');
local *MAKEFILE;
- open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
+ open MAKEFILE, "+< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
+ eval { flock MAKEFILE, LOCK_EX };
my $makefile = do { local $/; <MAKEFILE> };
- close MAKEFILE or die $!;
$makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
$makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
@@ -241,7 +387,8 @@ sub fix_up_makefile {
# XXX - This is currently unused; not sure if it breaks other MM-users
# $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;
- open MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
+ seek MAKEFILE, 0, SEEK_SET;
+ truncate MAKEFILE, 0;
print MAKEFILE "$preamble$makefile$postamble" or die $!;
close MAKEFILE or die $!;
@@ -265,4 +412,4 @@ sub postamble {
__END__
-#line 394
+#line 541
diff --git a/inc/Module/Install/Metadata.pm b/inc/Module/Install/Metadata.pm
index 653193d..cfe45b3 100644
--- a/inc/Module/Install/Metadata.pm
+++ b/inc/Module/Install/Metadata.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.91';
+ $VERSION = '1.00';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
@@ -19,7 +19,6 @@ my @scalar_keys = qw{
name
module_name
abstract
- author
version
distribution_type
tests
@@ -43,8 +42,11 @@ my @resource_keys = qw{
my @array_keys = qw{
keywords
+ author
};
+*authors = \&author;
+
sub Meta { shift }
sub Meta_BooleanKeys { @boolean_keys }
sub Meta_ScalarKeys { @scalar_keys }
@@ -176,43 +178,6 @@ sub perl_version {
$self->{values}->{perl_version} = $version;
}
-#Stolen from M::B
-my %license_urls = (
- perl => 'http://dev.perl.org/licenses/',
- apache => 'http://apache.org/licenses/LICENSE-2.0',
- artistic => 'http://opensource.org/licenses/artistic-license.php',
- artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php',
- lgpl => 'http://opensource.org/licenses/lgpl-license.php',
- lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php',
- lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html',
- bsd => 'http://opensource.org/licenses/bsd-license.php',
- gpl => 'http://opensource.org/licenses/gpl-license.php',
- gpl2 => 'http://opensource.org/licenses/gpl-2.0.php',
- gpl3 => 'http://opensource.org/licenses/gpl-3.0.html',
- mit => 'http://opensource.org/licenses/mit-license.php',
- mozilla => 'http://opensource.org/licenses/mozilla1.1.php',
- open_source => undef,
- unrestricted => undef,
- restrictive => undef,
- unknown => undef,
-);
-
-sub license {
- my $self = shift;
- return $self->{values}->{license} unless @_;
- my $license = shift or die(
- 'Did not provide a value to license()'
- );
- $self->{values}->{license} = $license;
-
- # Automatically fill in license URLs
- if ( $license_urls{$license} ) {
- $self->resources( license => $license_urls{$license} );
- }
-
- return 1;
-}
-
sub all_from {
my ( $self, $file ) = @_;
@@ -230,6 +195,8 @@ sub all_from {
die("The path '$file' does not exist, or is not a file");
}
+ $self->{values}{all_from} = $file;
+
# Some methods pull from POD instead of code.
# If there is a matching .pod, use that instead
my $pod = $file;
@@ -240,7 +207,7 @@ sub all_from {
$self->name_from($file) unless $self->name;
$self->version_from($file) unless $self->version;
$self->perl_version_from($file) unless $self->perl_version;
- $self->author_from($pod) unless $self->author;
+ $self->author_from($pod) unless @{$self->author || []};
$self->license_from($pod) unless $self->license;
$self->abstract_from($pod) unless $self->abstract;
@@ -350,6 +317,9 @@ sub version_from {
require ExtUtils::MM_Unix;
my ( $self, $file ) = @_;
$self->version( ExtUtils::MM_Unix->parse_version($file) );
+
+ # for version integrity check
+ $self->makemaker_args( VERSION_FROM => $file );
}
sub abstract_from {
@@ -360,7 +330,7 @@ sub abstract_from {
{ DISTNAME => $self->name },
'ExtUtils::MM_Unix'
)->parse_abstract($file)
- );
+ );
}
# Add both distribution and module name
@@ -385,11 +355,10 @@ sub name_from {
}
}
-sub perl_version_from {
- my $self = shift;
+sub _extract_perl_version {
if (
- Module::Install::_read($_[0]) =~ m/
- ^
+ $_[0] =~ m/
+ ^\s*
(?:use|require) \s*
v?
([\d_\.]+)
@@ -398,6 +367,16 @@ sub perl_version_from {
) {
my $perl_version = $1;
$perl_version =~ s{_}{}g;
+ return $perl_version;
+ } else {
+ return;
+ }
+}
+
+sub perl_version_from {
+ my $self = shift;
+ my $perl_version=_extract_perl_version(Module::Install::_read($_[0]));
+ if ($perl_version) {
$self->perl_version($perl_version);
} else {
warn "Cannot determine perl version info from $_[0]\n";
@@ -417,59 +396,164 @@ sub author_from {
([^\n]*)
/ixms) {
my $author = $1 || $2;
- $author =~ s{E<lt>}{<}g;
- $author =~ s{E<gt>}{>}g;
+
+ # XXX: ugly but should work anyway...
+ if (eval "require Pod::Escapes; 1") {
+ # Pod::Escapes has a mapping table.
+ # It's in core of perl >= 5.9.3, and should be installed
+ # as one of the Pod::Simple's prereqs, which is a prereq
+ # of Pod::Text 3.x (see also below).
+ $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
+ {
+ defined $2
+ ? chr($2)
+ : defined $Pod::Escapes::Name2character_number{$1}
+ ? chr($Pod::Escapes::Name2character_number{$1})
+ : do {
+ warn "Unknown escape: E<$1>";
+ "E<$1>";
+ };
+ }gex;
+ }
+ elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) {
+ # Pod::Text < 3.0 has yet another mapping table,
+ # though the table name of 2.x and 1.x are different.
+ # (1.x is in core of Perl < 5.6, 2.x is in core of
+ # Perl < 5.9.3)
+ my $mapping = ($Pod::Text::VERSION < 2)
+ ? \%Pod::Text::HTML_Escapes
+ : \%Pod::Text::ESCAPES;
+ $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
+ {
+ defined $2
+ ? chr($2)
+ : defined $mapping->{$1}
+ ? $mapping->{$1}
+ : do {
+ warn "Unknown escape: E<$1>";
+ "E<$1>";
+ };
+ }gex;
+ }
+ else {
+ $author =~ s{E<lt>}{<}g;
+ $author =~ s{E<gt>}{>}g;
+ }
$self->author($author);
} else {
warn "Cannot determine author info from $_[0]\n";
}
}
-sub license_from {
+#Stolen from M::B
+my %license_urls = (
+ perl => 'http://dev.perl.org/licenses/',
+ apache => 'http://apache.org/licenses/LICENSE-2.0',
+ apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1',
+ artistic => 'http://opensource.org/licenses/artistic-license.php',
+ artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php',
+ lgpl => 'http://opensource.org/licenses/lgpl-license.php',
+ lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php',
+ lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html',
+ bsd => 'http://opensource.org/licenses/bsd-license.php',
+ gpl => 'http://opensource.org/licenses/gpl-license.php',
+ gpl2 => 'http://opensource.org/licenses/gpl-2.0.php',
+ gpl3 => 'http://opensource.org/licenses/gpl-3.0.html',
+ mit => 'http://opensource.org/licenses/mit-license.php',
+ mozilla => 'http://opensource.org/licenses/mozilla1.1.php',
+ open_source => undef,
+ unrestricted => undef,
+ restrictive => undef,
+ unknown => undef,
+);
+
+sub license {
my $self = shift;
- if (
- Module::Install::_read($_[0]) =~ m/
- (
- =head \d \s+
- (?:licen[cs]e|licensing|copyright|legal)\b
- .*?
- )
- (=head\\d.*|=cut.*|)
- \z
- /ixms ) {
- my $license_text = $1;
- my @phrases = (
- 'under the same (?:terms|license) as (?:perl|the perl programming language) itself' => 'perl', 1,
- 'GNU general public license' => 'gpl', 1,
- 'GNU public license' => 'gpl', 1,
- 'GNU lesser general public license' => 'lgpl', 1,
- 'GNU lesser public license' => 'lgpl', 1,
- 'GNU library general public license' => 'lgpl', 1,
- 'GNU library public license' => 'lgpl', 1,
- 'BSD license' => 'bsd', 1,
- 'Artistic license' => 'artistic', 1,
- 'GPL' => 'gpl', 1,
- 'LGPL' => 'lgpl', 1,
- 'BSD' => 'bsd', 1,
- 'Artistic' => 'artistic', 1,
- 'MIT' => 'mit', 1,
- 'proprietary' => 'proprietary', 0,
- );
- while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
- $pattern =~ s{\s+}{\\s+}g;
- if ( $license_text =~ /\b$pattern\b/i ) {
- $self->license($license);
- return 1;
- }
+ return $self->{values}->{license} unless @_;
+ my $license = shift or die(
+ 'Did not provide a value to license()'
+ );
+ $license = __extract_license($license) || lc $license;
+ $self->{values}->{license} = $license;
+
+ # Automatically fill in license URLs
+ if ( $license_urls{$license} ) {
+ $self->resources( license => $license_urls{$license} );
+ }
+
+ return 1;
+}
+
+sub _extract_license {
+ my $pod = shift;
+ my $matched;
+ return __extract_license(
+ ($matched) = $pod =~ m/
+ (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?)
+ (=head \d.*|=cut.*|)\z
+ /xms
+ ) || __extract_license(
+ ($matched) = $pod =~ m/
+ (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?)
+ (=head \d.*|=cut.*|)\z
+ /xms
+ );
+}
+
+sub __extract_license {
+ my $license_text = shift or return;
+ my @phrases = (
+ '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1,
+ '(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1,
+ 'Artistic and GPL' => 'perl', 1,
+ 'GNU general public license' => 'gpl', 1,
+ 'GNU public license' => 'gpl', 1,
+ 'GNU lesser general public license' => 'lgpl', 1,
+ 'GNU lesser public license' => 'lgpl', 1,
+ 'GNU library general public license' => 'lgpl', 1,
+ 'GNU library public license' => 'lgpl', 1,
+ 'GNU Free Documentation license' => 'unrestricted', 1,
+ 'GNU Affero General Public License' => 'open_source', 1,
+ '(?:Free)?BSD license' => 'bsd', 1,
+ 'Artistic license' => 'artistic', 1,
+ 'Apache (?:Software )?license' => 'apache', 1,
+ 'GPL' => 'gpl', 1,
+ 'LGPL' => 'lgpl', 1,
+ 'BSD' => 'bsd', 1,
+ 'Artistic' => 'artistic', 1,
+ 'MIT' => 'mit', 1,
+ 'Mozilla Public License' => 'mozilla', 1,
+ 'Q Public License' => 'open_source', 1,
+ 'OpenSSL License' => 'unrestricted', 1,
+ 'SSLeay License' => 'unrestricted', 1,
+ 'zlib License' => 'open_source', 1,
+ 'proprietary' => 'proprietary', 0,
+ );
+ while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
+ $pattern =~ s#\s+#\\s+#gs;
+ if ( $license_text =~ /\b$pattern\b/i ) {
+ return $license;
}
}
+ return '';
+}
- warn "Cannot determine license info from $_[0]\n";
- return 'unknown';
+sub license_from {
+ my $self = shift;
+ if (my $license=_extract_license(Module::Install::_read($_[0]))) {
+ $self->license($license);
+ } else {
+ warn "Cannot determine license info from $_[0]\n";
+ return 'unknown';
+ }
}
sub _extract_bugtracker {
- my @links = $_[0] =~ m#L<(\Qhttp://rt.cpan.org/\E[^>]+)>#g;
+ my @links = $_[0] =~ m#L<(
+ \Qhttp://rt.cpan.org/\E[^>]+|
+ \Qhttp://github.com/\E[\w_]+/[\w_]+/issues|
+ \Qhttp://code.google.com/p/\E[\w_\-]+/issues/list
+ )>#gx;
my %links;
@links{@links}=();
@links=keys %links;
@@ -485,7 +569,7 @@ sub bugtracker_from {
return 0;
}
if ( @links > 1 ) {
- warn "Found more than on rt.cpan.org link in $_[0]\n";
+ warn "Found more than one bugtracker link in $_[0]\n";
return 0;
}
@@ -532,8 +616,15 @@ sub _perl_version {
return $v;
}
-
-
+sub add_metadata {
+ my $self = shift;
+ my %hash = @_;
+ for my $key (keys %hash) {
+ warn "add_metadata: $key is not prefixed with 'x_'.\n" .
+ "Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/;
+ $self->{values}->{$key} = $hash{$key};
+ }
+}
######################################################################
diff --git a/inc/Module/Install/Win32.pm b/inc/Module/Install/Win32.pm
index f2f99df..edc18b4 100644
--- a/inc/Module/Install/Win32.pm
+++ b/inc/Module/Install/Win32.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.91';
+ $VERSION = '1.00';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
diff --git a/inc/Module/Install/WriteAll.pm b/inc/Module/Install/WriteAll.pm
index 12471e5..d0f6599 100644
--- a/inc/Module/Install/WriteAll.pm
+++ b/inc/Module/Install/WriteAll.pm
@@ -6,7 +6,7 @@ use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.91';;
+ $VERSION = '1.00';
@ISA = qw{Module::Install::Base};
$ISCORE = 1;
}
@@ -26,7 +26,10 @@ sub WriteAll {
$self->check_nmake if $args{check_nmake};
unless ( $self->makemaker_args->{PL_FILES} ) {
- $self->makemaker_args( PL_FILES => {} );
+ # XXX: This still may be a bit over-defensive...
+ unless ($self->makemaker(6.25)) {
+ $self->makemaker_args( PL_FILES => {} ) if -f 'Build.PL';
+ }
}
# Until ExtUtils::MakeMaker support MYMETA.yml, make sure
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list