FunctionalPerl
view release on metacpan or search on metacpan
examples/csv_to_xml view on Meta::CPAN
my $location = (-l $0) ? abs_path($0) : $0;
$location =~ /(.*?)([^\/]+?)_?\z/s or die "?";
($mydir, $myname) = ($1, $2);
}
use lib "$mydir/../lib";
sub usage {
print "usage: $myname [-o xmlfile] csvfile(s)
Open and read csvfile containing CSV with 4 columns, and write it to
xmlfile or stdout as XML. Does streaming, i.e. only loads one row
(plus some buffering) into memory at a time.
";
exit(@_ ? 1 : 0);
}
use Getopt::Long;
our $verbose = 0;
our $outpath;
GetOptions(
examples/diff_to_html view on Meta::CPAN
($mydir, $myname) = ($1, $2);
}
use lib "$mydir/../lib";
sub usage {
print "usage: $myname < file.diff > file-diff.html
Turn a textual diff as output by `git diff` into HTML format with
some coloring.
Uses streaming and hence works with arbitrarily long inputs.
";
exit(@_ ? 1 : 0);
}
use Getopt::Long;
our $verbose = 0;
GetOptions("verbose" => \$verbose, "help" => sub {usage},) or exit 1;
usage if @ARGV;
use Method::Signatures;
examples/gen-csv view on Meta::CPAN
$location =~ /(.*?)([^\/]+?)_?\z/s or die "?";
($mydir, $myname) = ($1, $2);
}
use lib "$mydir/../lib";
sub usage {
print "usage: $myname outpath numrows
Write some useless number series in CSV format.
Purpose: example and test for lazy list (streaming) code (check for
leaks/memory retention).
";
exit(@_ ? 1 : 0);
}
use Getopt::Long;
our $verbose = 0;
GetOptions("verbose" => \$verbose, "help" => sub {usage},) or exit 1;
usage unless @ARGV == 2;
functional_XML/README.md view on Meta::CPAN
`HTML::TreeBuilder`).
Its in-memory representation are `PXML::Element` (or subclassed)
objects. Serialization is done using functions/procedures from
`PXML::Serialize` (also, using `PXML::Preserialize` if necessary for
performance).
The body of elements can be a mix of standard Perl arrays,
`FP::PureArray`s, linked lists based on `FP::List`, and promises
(`FP::Lazy`, `FP::Stream`), the latter of which allow for the
generation of streaming output (which means the document is generated
while it is being serialized, thus there's no memory needed to hold
the whole document at once).
Direct creation of XML elements:
use PXML::Element;
my $element = PXML::Element->new
("a", {href=> "http://myserver.com"}, ["my server"]);
Using 'tag functions' for shorter code:
lib/FP/Abstract/Sequence.pm view on Meta::CPAN
FP::List::cons($value, $rest->intersperse($value)))
}
}
}
# XX better name?
sub extreme {
@_ == 2 or fp_croak_arity 2;
my ($self, $cmp) = @_;
# XXX: fold_right is good for FP::Stream streaming. left fold will
# be better for FP::List. How? Add fold_left for explicit left
# folding and make fold chose the preferred solution for
# order-irrelevant folding?
$self->rest->fold(
sub {
my ($v, $res) = @_;
my $c = &$cmp($v, $res);
$c < 0 ? $v : $res
},
$self->first
lib/PXML/Serialize.pm view on Meta::CPAN
redo LP;
} elsif (is_somearray($v)) {
# COPY-PASTE. Really should refactor
# _pxml_print_fragment_fast into local hash-table
# based dispatcher.
no warnings "recursion"; # hu.
for (@$v) {
# XXX use Keep around $_ to prevent mutation of tree?
# nope, can't, will prevent streaming.
_pxml_print_fragment_fast($_, $fh, $html5compat,
$void_element_h);
}
} elsif (is_pxmlflush $v) {
flush $fh or die $!
} else {
# Fallback for references, XX copy-paste
print $fh object_force_escape($v,
"pxml_serialized_body_string", \&content_escape,
$fh)
or die $!;
}
}
} else {
if (is_somearray($v)) {
no warnings "recursion"; # hu.
for (@$v) {
# XXX use Keep around $_ to prevent mutation of tree?
# nope, can't, will prevent streaming.
_pxml_print_fragment_fast($_, $fh, $html5compat,
$void_element_h);
}
}
# 'force' doesn't evaluate CODE (probably rightly so),
# thus need to be explicit if we want 'late binding'
# (e.g. reference to dynamic variables) during
# serialization
elsif ($ref eq "CODE") {
( run in 0.287 second using v1.01-cache-2.11-cpan-4d50c553e7e )