view release on metacpan or search on metacpan
examples/dbi view on Meta::CPAN
BEGIN {
my $location = (-l $0) ? abs_path($0) : $0;
$location =~ /(.*?)([^\/]+?)_?\z/s or die "?";
($mydir, $myname) = ($1, $2);
}
use lib "$mydir/../lib";
use Chj::TEST
use => "DBD::CSV",
use => "FP::DBI"; # 'DBI' really, indirectly
use PXML::XHTML ":all";
use FP::Weak;
use Chj::Backtrace;
our $db = FP::DBI->connect("dbi:CSV:");
$db->{csv_sep_char} = ";";
our $get = $db->prepare("select * from examples/csv_to_xml-example.csv");
examples/definitionlists view on Meta::CPAN
GetOptions("verbose" => \$verbose, "help" => sub {usage},) or exit 1;
usage unless @ARGV == 2;
my ($infile, $outfile) = @ARGV;
use FP::Predicates qw(is_string);
use FP::List qw(mixed_flatten);
use FP::PureArray;
use Chj::TEST ":all";
use Chj::xIOUtil qw(xgetfile_utf8 xputfile_utf8);
use PXML::XHTML ":all";
use PXML::Serialize qw(puthtmlfile);
use PXML qw(is_pxml_element); # XX: why does it not complain when
# trying to import from PXML::Element?
use FP::Ops qw(the_method);
#debug
use FP::Ops ":all"; #qw(the_method);
use FP::Combinators ":all";
use Chj::ruse;
examples/diff_to_html view on Meta::CPAN
use Getopt::Long;
our $verbose = 0;
GetOptions("verbose" => \$verbose, "help" => sub {usage},) or exit 1;
usage if @ARGV;
use Method::Signatures;
use FP::Stream ":all";
use FP::IOStream ":all";
use PXML::Serialize qw(puthtmlfile);
use PXML::XHTML ":all";
use FP::Ops ":all";
use Chj::xopen "glob_to_fh";
our $lines = fh_to_stream(
glob_to_fh(*STDIN, "utf-8"),
the_method("xreadline_chomp"),
the_method("xclose")
);
our $html = HTML(
examples/pdf-to-html view on Meta::CPAN
"single-page" => \$opt_single,
"outdir=s" => \$opt_outdir,
) or exit 1;
use FP::IOStream qw(xdirectory_paths);
use FP::List qw(list cons);
use FP::Stream qw(Keep);
use Chj::xperlfunc qw(xstat xxsystem_safe xunlink basename dirname);
use FP::Combinators qw(compose_scalar);
use FP::Ops qw(the_method real_cmp regex_match regex_xsubstitute);
use PXML::XHTML ':all';
use PXML::Serialize qw(puthtmlfile);
use FP::Array_sort qw(on);
use Chj::xIOUtil qw(xputfile_utf8);
use Chj::TEST ":all";
use FP::Div qw(min max);
use Chj::singlequote qw(quote_javascript);
sub note {
print STDERR "$myname: note: ", @_, "\n";
}
functional_XML/README.md view on Meta::CPAN
`PXML::Tags`,
`PXML::Serialize`,
`PXML::Preserialize`,
`PXML::Util`
## Comparison with CGI.pm
When generating HTML, `CGI`'s tag functions seem similar, what are
the differences?
- PXML::XHTML chooses upper-case constructor names to reduce the
chances for conflicts; for example using "tr" for `<TR></TR>`
conflicts with the tr builtin Perl operator.
- `CGI`'s creators return strings, whereas PXML::XHTML returns
PXML::Element objects. The former might have O(n^2) complexity with the
size of documents (getting slower to concatenate big strings),
while the latter should have constant overhead. Also, PXML can be
inspected after creation, an option not possible with `CGI`
(without using an XML parser).
- PXML serialization always escapes strings, hence
is safe against XSS, while `CGI` does/is not.
- PXML has chosen not to support dashes on attributes,
functional_XML/t/div view on Meta::CPAN
our ($mydir, $myname);
BEGIN {
$0 =~ /(.*?)([^\/]+)\z/s or die "?";
($mydir, $myname) = ($1, $2);
}
use lib "$mydir/../../lib";
use Chj::TEST ":all";
use PXML::XHTML ":all";
use PXML::Serialize "pxml_print_fragment_fast";
use FP::Lazy;
use FP::List;
use FP::Stream;
use FP::Array ":all"; # XXX inconsistency in export directives
use FP::PureArray;
TEST_STDOUT {
pxml_print_fragment_fast(A({ href => "hah" }, "Hello ", I("World", B("!"))),
*STDOUT{IO})
functional_XML/test view on Meta::CPAN
use Cwd 'abs_path';
our ($mydir, $myname);
BEGIN {
my $location = (-l $0) ? abs_path($0) : $0;
$location =~ /(.*?)([^\/]+?)_?\z/s or die "?";
($mydir, $myname) = ($1, $2);
}
use lib "$mydir/../lib";
use PXML::XHTML ':all';
use PXML::Serialize;
use utf8;
sub page {
my ($title, $mtime, $main) = @_;
HTML(
HEAD(TITLE($title)),
BODY(
$main,
functional_XML/testlazy view on Meta::CPAN
use Cwd 'abs_path';
our ($mydir, $myname);
BEGIN {
my $location = (-l $0) ? abs_path($0) : $0;
$location =~ /(.*?)([^\/]+?)_?\z/s or die "?";
($mydir, $myname) = ($1, $2);
}
use lib "$mydir/../lib";
use PXML::XHTML ':all';
use FP::Lazy;
use FP::List;
use PXML::Serialize;
use utf8;
$| = 1;
sub countdown {
my ($i) = @_;
htmlgen/FunctionalPerl/Htmlgen/Htmlparse.pm view on Meta::CPAN
# (^ actually mutates $t into the HTML::Element object already, ugh)
$e->find_by_tag_name($whichtag)
}
my $attsubname_re = qr/\w[\w-]*/; # XX OK?
my $attname_re
= qr/$attsubname_re(?::$attsubname_re)?/; # with namespace, optionally
sub htmlmap($e) {
__ '(HTML::Element) -> PXML::_::XHTML '
. '-- convert output from HTML::TreeBuilder to PXML::XHTML (PXML::Element)';
my $name = lc($e->tag);
my $atts = {};
for ($e->all_external_attr_names) {
next if $_ eq "/";
# HACK: accept namespaces in attribute names
die "invalid attribute name string '$_'" unless /^$attname_re\z/s;
$$atts{ lc $_ } = $e->attr($_);
}
# XX unsafe, if we don't check that a corresponding constructor
# exists! Could fall back to just PXML::Element (which
# PXML::_::XHTML is):
PXML::_::XHTML->new(
$name, $atts,
[
map {
if (ref $_) {
# another HTML::Element
no warnings "recursion"; # XX should rather sanitize input?
htmlmap($_)
} else {
htmlgen/FunctionalPerl/Htmlgen/Linking.pm view on Meta::CPAN
use warnings;
use warnings FATAL => 'uninitialized';
use experimental "signatures";
use Sub::Call::Tail;
package FunctionalPerl::Htmlgen::Linking::Anchors {
# add anchors
use PXML::XHTML ":all";
use FP::Struct [] => "FunctionalPerl::Htmlgen::PXMLMapper";
sub match_element_names($self) { [qw(h1 h2 h3 h4)] }
sub map_element ($self, $e, $uplist) {
my $text = $e->text;
$text =~ s/ /_/sg;
A({ name => $text }, $e)
}
_END_
}
package FunctionalPerl::Htmlgen::Linking::code {
use FP::List;
use FP::Predicates;
use FunctionalPerl::Htmlgen::PathUtil qw(path_diff);
use PXML::XHTML ":all";
use Chj::CPAN::ModulePODUrl 'perhaps_module_pod_url';
use FP::Memoizing 'memoizing_to_dir';
use FunctionalPerl::Indexing qw(identifierInfos_by_name);
use FP::Carp;
our $podurl_cache = ".ModulePODUrl-cache";
mkdir $podurl_cache;
# NOTE: ignores are handled further down, see $ignore_module_name
*xmaybe_module_pod_url = memoizing_to_dir $podurl_cache, sub {
htmlgen/FunctionalPerl/Htmlgen/MarkdownPlus.pm view on Meta::CPAN
# bundled with this file.
#
=head1 NAME
FunctionalPerl::Htmlgen::MarkdownPlus
=head1 SYNOPSIS
use FunctionalPerl::Htmlgen::MarkdownPlus qw(markdownplus_parse);
use PXML::XHTML qw(BODY);
my $mediawikitoken = rand;
# passed to mediawiki_prepare from FunctionalPerl::Htmlgen::Mediawiki
my ($h1,$body1) = markdownplus_parse(
"# Hi\n\nHello [World](http://world).\n", # markdownplusstr
"Hi too", # alternative_title
$mediawikitoken);
is $h1->string, '<h1>Hi</h1>';
is BODY($body1)->string,
'<body><p>Hello <a href="http://world">World</a>.</p></body>';
htmlgen/FunctionalPerl/Htmlgen/MarkdownPlus.pm view on Meta::CPAN
use Sub::Call::Tail;
use Exporter "import";
our @EXPORT = qw();
our @EXPORT_OK = qw(markdownplus_parse);
our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
use FP::Docstring;
use Chj::TEST;
use PXML qw(is_pxml_element);
use PXML::XHTML ":all";
use FP::Stream ":all";
use FunctionalPerl::Htmlgen::Htmlparse 'htmlparse';
use Text::Markdown 'markdown';
use FP::Lazy;
use FunctionalPerl::Htmlgen::Mediawiki qw(mediawiki_prepare);
# Return <h1> element if available, and rest.
sub pxml_body_split_h1($body) {
my $b = stream_mixed_flatten $body;
my ($v, $rest) = $b->first_and_rest;
htmlgen/FunctionalPerl/Htmlgen/Mediawiki.pm view on Meta::CPAN
use Exporter "import";
our @EXPORT = qw();
our @EXPORT_OK = qw(mediawiki_prepare mediawiki_replace mediawiki_rexpand
mediawiki_expand);
our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
use FP::Docstring;
use Chj::chompspace;
use Chj::TEST ":all";
use PXML::XHTML ":all";
use FP::Show;
use URI;
# and for text display we need to *decode* URIs..
# COPY from chj-bin's `urldecode`, now modified by having our own
# uri_escape
use Encode;
# Adapted copy from URI::Escape
sub uri_unescape($str) {
htmlgen/FunctionalPerl/Htmlgen/Toc.pm view on Meta::CPAN
use strict;
use warnings;
use warnings FATAL => 'uninitialized';
use experimental "signatures";
use Sub::Call::Tail;
use FP::StrictList;
use FP::List;
use Chj::TEST;
use PXML::XHTML ":all";
use FP::Stream qw(stream_mixed_state_fold_right);
use PXML ":all";
use FP::Predicates qw(is_natural);
sub rindices_numberstring($rindices) {
is_null($rindices)
? ""
: $rindices->reverse->map(sub($i) {"$i."})->strings_join("") . " "
}
TEST { rindices_numberstring(list()) } "";
TEST { rindices_numberstring(list(2, 1)) } "1.2. ";
package FunctionalPerl::Htmlgen::Toc::TocNodeBase {
use FP::StrictList;
use FP::Predicates;
use FP::List;
use PXML::XHTML ":all";
use FP::Struct [[\&is_strictlist, "subnodes"]];
sub subnodes_length($self) {
$self->subnodes->length
}
sub subnodes_add ($self, $node) {
is_instance_of $node, "FunctionalPerl::Htmlgen::Toc::TocNode"
or die "wrong type";
htmlgen/FunctionalPerl/Htmlgen/Toc.pm view on Meta::CPAN
# XX keep some formatting?
$self->header->text
}
_END_
}
package FunctionalPerl::Htmlgen::Toc::TocRootNode {
use FP::List;
use PXML::XHTML ":all";
use FP::Struct ["header_pxml_for_toc"],
"FunctionalPerl::Htmlgen::Toc::TocNodeBase";
sub name($self) {undef}
sub html($self) {
DIV({ class => "toc_box" }, $self->html_with_parents(null))
}
htmlgen/gen view on Meta::CPAN
# and the htmlgen/ directory
use lib $mydir;
use Getopt::Long;
use FP::Docstring;
use Chj::Backtrace;
use Hash::Util 'lock_hash';
use Chj::xperlfunc qw(basename dirname);
use Chj::xIOUtil qw(xgetfile_utf8 xcopyfile);
use FP::HashSet ":all";
use PXML::XHTML ":all";
use PXML::Serialize 'puthtmlfile';
use FP::Array ":all";
use File::Spec;
use FP::Array_sort;
use FP::Ops qw(string_cmp real_cmp the_method cut_method);
use FP::Equal qw(equal);
use FP::autobox;
use Chj::TEST ":all";
use FP::List qw(is_pair list);
use PXML::Util qw(pxml_map_elements_exhaustively);
lib/FunctionalPerl.pm view on Meta::CPAN
qw(FP::Combinators FP::Combinators2
FP::Cmp
FP::Ops FP::Div
FP::Predicates
FP::Optional FP::Values
FP::Memoizing FP::Currying
FP::Untainted
:show :equal :failures)
],
":git" => [qw(FP::Git::Repository)],
":pxml" => [qw(PXML::Util PXML::XHTML PXML::Serialize)],
":ast" => [qw(FP::AST::Perl)],
":numbers" => [qw(FP::BigInt)],
":chars" => [qw(FP::Char)],
":sequences" => [
qw(FP::List FP::MutableArray
FP::Array FP::Array_sort
FP::PureArray
:streams)
],
lib/PXML.pm view on Meta::CPAN
# bundled with this file.
#
=head1 NAME
PXML - functional XML handling, general functions
=head1 SYNOPSIS
use PXML qw(is_pxml_element);
use PXML::XHTML qw(P);
ok is_pxml_element P();
is P("Hi <there>")->string, '<p>Hi <there></p>';
use PXML ":all";
is(pxmlbody("foo")->string, "foo");
=head1 DESCRIPTION
lib/PXML/Element.pm view on Meta::CPAN
} else {
""
}
}
sub text {
my $s = shift;
_text($s->body)
}
# only for debugging? Doesn't emit XML/XHTML prologues! Also, ugly
# monkey-access to PXML::Serialize. Circular dependency, too.
sub string {
my $s = shift;
require PXML::Serialize;
capture_stdout {
PXML::Serialize::pxml_print_fragment_fast($s, *STDOUT);
}
}
lib/PXML/Preserialize.pm view on Meta::CPAN
# bundled with this file.
#
=head1 NAME
PXML::Preserialize - faster PXML templating through preserialization
=head1 SYNOPSIS
use PXML::Preserialize qw(pxmlfunc pxmlpre);
use PXML::XHTML qw(A B);
my $link_normal = sub {
my ($href,$body)=@_;
A {href=> $href}, $body
};
my $link_fast = pxmlfunc {
my ($href,$body)=@_; # can take up to 10[?] arguments.
A {href=> $href}, $body
};
lib/PXML/Preserialize/t.pm view on Meta::CPAN
package PXML::Preserialize::t;
use strict;
use warnings;
use warnings FATAL => 'uninitialized';
use Chj::TEST;
use PXML qw(pxmlbody);
use PXML::Preserialize qw(pxmlfunc pxmlpre);
use PXML::XHTML qw(A B);
my $link_normal = sub {
my ($href, $body) = @_;
A { href => $href }, $body
};
my $link_fast = pxmlfunc {
my ($href, $body) = @_; # can take up to 10[?] arguments.
A { href => $href }, $body
};
lib/PXML/SVG.pm view on Meta::CPAN
our @EXPORT_OK = ('svg', '$nbsp', map { $$_[0] } @$funcs);
our %EXPORT_TAGS = (all => \@EXPORT_OK);
{
package PXML::PSVG;
our @ISA = "PXML::Element";
# serialize to HTML5 compatible representation: -- nope, not
# necessary for SVG, ok? Assuming XHTML always? And different tags
# anyway, ok?
}
1
lib/PXML/Serialize.pm view on Meta::CPAN
my ($v, $fh, $maybe_lang) = @_;
weaken $_[0] if ref $_[0]; # ref check perhaps unnecessary here
if (not ref $v or (defined(blessed $v) and not $v->isa("PXML::Element"))) {
die "not an element: " . (show $v);
}
if (not "html" eq $v->name) {
die "not an 'html' element: " . (show $v);
}
xprint($fh, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
xprint($fh,
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
);
# add attributes to toplevel element
my $v2 = $v->maybe_attributes ? $v : $v->attributes_set(
do {
my $lang = $maybe_lang
or die
"missing 'lang' attribute from html element and no lang option given";
+{
xmlns => "http://www.w3.org/1999/xhtml",
lib/PXML/Serialize/t.pm view on Meta::CPAN
=cut
package PXML::Serialize::t;
use strict;
use warnings;
use warnings FATAL => 'uninitialized';
use Chj::TEST;
use PXML::Serialize qw(pxml_print_fragment_fast);
use PXML::XHTML ":all";
use PXML qw(pxmlflush);
TEST_STDOUT { pxml_print_fragment_fast ["abc", P(2)], *STDOUT }
'abc<p>2</p>';
TEST_STDOUT { pxml_print_fragment_fast ["abc"], *STDOUT }
'abc';
TEST_STDOUT {
pxml_print_fragment_fast P({ foo => ["a", ["b", pxmlflush, "c"], "d"] },
"abc"), *STDOUT{IO}
lib/PXML/Util.pm view on Meta::CPAN
# XX TCO?
&$elementfn($e->body_map($inferior_map), $uplist)
},
$maybe_otherfn,
$maybe_uplist
)
}
sub t_data {
require PXML::XHTML;
import PXML::XHTML qw(P B A CODE);
P("foo", B("bar", undef, stream_iota(5)->take(4)))
}
TEST { t_data->string }
'<p>foo<b>bar5678</b></p>';
TEST {
pxml_eager_map(
t_data,
sub {
lib/PXML/XHTML.pm view on Meta::CPAN
for (@$funcs) {
my ($name, $fn) = @$_;
no strict 'refs';
*{"PXML::XHTML::$name"} = $fn
}
our @EXPORT_OK = ('$nbsp', map { $$_[0] } @$funcs);
our %EXPORT_TAGS = (all => \@EXPORT_OK);
package PXML::_::XHTML {
our @ISA = "PXML::Element";
# serialize to HTML5 compatible representation:
sub require_printing_nonvoid_elements_nonselfreferential {
1
}
use PXML::HTML5 '$html5_void_element_h';
sub void_element_h {
$html5_void_element_h
}
use FP::Show ();
# This "should" be moved to PXML::Element except that we only know
# in the HTML case how to map back tag names to constructors (XX
# is it actually safe here?). (Would have to store what mapping
# functions were created under which function names for which tag
# names, and which packages they were exported to.) XXX at least
# move to common base class of XHTML and HTML5.
sub FP_Show_show {
my ($s, $show) = @_;
my $a = $s->maybe_attributes;
my $b = $s->body;
(
uc($s->name) . "("
. join(", ",
(defined($a) and keys %$a) ? &$show($a) : (),
ref($b) eq "ARRAY"
? join(", ", map { &$show($_) } @$b)
t/functional_XML-test.expected view on Meta::CPAN
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><title>example page - Hello World</title></head><body><h1>Hello World</h1><p>Garçon méchanique, "1 < 2" is true. <a href=""1 < 2"">this will be 404</a></p><tab...
t/testlazy.expected view on Meta::CPAN
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><title>example page - Hello World</title></head><body><h1>Hello World</h1><p>Garçon méchanique, "1 < 2" is true. <a href=""1 < 2"">this will be 404</a></p><table...
t/testlazy10.expected view on Meta::CPAN
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><title>example page - Hello World</title></head><body><h1>Hello World</h1><p>Garçon méchanique, "1 < 2" is true. <a href=""1 < 2"">this will be 404</a></p><table...
website/gen-config.pl view on Meta::CPAN
use strict;
use warnings;
use warnings FATAL => 'uninitialized';
use utf8;
use experimental "signatures";
our ($mydir, $gitrepository); # 'import' from main
use PXML::XHTML ":all";
use Clone 'clone';
use FP::Lazy;
# htmlgen is run with CWD set to website/
my $logocfg = require "./logo.pl";
my $css_path0 = "FP.css";
my $version_numrevisions = lazy {
my $describe = $gitrepository->describe();
website/logo.pl view on Meta::CPAN
use strict;
use warnings;
use warnings FATAL => 'uninitialized';
use PXML::XHTML ":all";
my $homeurl = "http://functional-perl.org";
my $logo_from_base = "FP-logo.png";
sub {
my ($path0) = @_;
+{
homeurl => $homeurl,
logo => DIV(
{ class => "header" },