XML::Literal - Syntax suppor for XML literals


XML-Literal documentation Contained in the XML-Literal distribution.

Index


Code Index:

NAME

Top

XML::Literal - Syntax suppor for XML literals

SYNOPSIS

Top

    # This is not a source filter: it just augments glob().
    use XML::Simple;
    use XML::Literal \&XMLin;

    # Simple element
    my $xml1 = <hr/>;

    # With variable interpolation
    my $xml2 = <input value='$ARGV[0]' />;

    # With an extra pair of angle brackets
    my $xml3 = < <a href='/'> Some Text </a> >;

    # With escaped angle brackets 
    my $xml4 = <a href='/'\> Some Text \</a>;

    # Direct call to the xml-building glob'' constructor
    my $xml5 = glob'
        <p><em>
            Some Text
        </em></p>
    ';

    # This does not look like XML, so it's still shell glob
    my @files = <*.*>;

DESCRIPTION

Top

This module takes one function at its use line. Afterwards, all single-line <...> calls that looks like a XML literal will be processed with that function, instead of the built-in shell glob.

Support for qx<...> overriding for multiline XML literals is planned for Perl 5.10.

AUTHORS

Top

Audrey Tang <cpan@audreyt.org>

COPYRIGHT (The "MIT" License)

Top


XML-Literal documentation Contained in the XML-Literal distribution.

package XML::Literal;

use 5.006;
use strict;
use warnings;
use File::Glob ();

$XML::Literal::VERSION = '0.02';

sub import {
    my $class       = shift;
    my $callback    = shift;

    no warnings 'redefine';
    *CORE::GLOBAL::glob = sub {
        if ($_[0] =~ m{^\s*<}) {
            # Looks like < <tag> >
            goto &$callback;
        }
        elsif ($_[0] =~ m{/\w*\s*$}) {
            # Looks like <tag/> or <tag\>...\</tag>
            @_ = "<$_[0]>";
            goto &$callback;
        }
        else {
            # Looks like file globbing
            goto &File::Glob::glob;
        }
    };
}

1;

__END__