File-ANVL
view release on metacpan or search on metacpan
lib/File/ANVL.pm view on Meta::CPAN
Smith, Jo
home: 555-1234
work: 555-9876
in which case they contain the line number and value, respectively. Array
element 1 always contains a string naming the format of the input, such
as, "ANVL", "JSON", "XML", etc.
The remaining triples are free form except that the values will have been
drawn from the original format and possibly decoded. The first item
("lineno") in each remaining triple is a number followed by a character,
for example, "34:" or "6#". The number indicates the line number (or
octet offset, depending on the origin format) of the start of the
element. The character is either ':' to indicate a real element or '#'
to indicate a comment; if the latter, the element name has no defined
meaning and the comment is contained in the value. Here's example code
that reads a 3-element record and reformats it.
($msg = File::ANVL::anvl_recarray('
a: b c
lib/File/OM.pm view on Meta::CPAN
sub name_encode { # OM::ANVL
my ($self, $s) = (shift, shift);
defined($s) or return '';
#$s =~ s/^\s+//;
#$s =~ s/\s+$//; # trim both ends
#$s =~ s/\s+/ /g; # squeeze multiple \s to one space
# xxx keep doubling %?
$s =~ s/%/%%/g; # to preserve literal %, double it
# xxx what about granvl?
# yyy must be decoded by receiver
#$s =~ s/:/%3a/g; # URL-encode all colons (%cn)
$s =~ s{ # URL-encode all colons and whitespace
([=:<\s]) # \s matches [ \t\n\f] etc.
}{ # = and < anticipate ANVL extensions
sprintf("%%%02x", ord($1)) # replacement hex code
}xeg;
# This next line takes care of the mainstream case of names that
# contain spaces. It makes sure that for every run of one or more
lib/File/OM.pm view on Meta::CPAN
#my $value_start = $initial_newlines || ($value ? ' ' : '');
# xxxx is this the right place to enforce the space after ':'?
# xxx is there a linear whitespace char class??
# problem is that \s includes \n
#$s =~ s/^\s+//;
#$s =~ s/\s+$//; # trim both ends
$s =~ s/%/%%/g; # to preserve literal %, double it
# yyy must be decoded by receiver
$s =~ s{ # URL-encode newlines in portable way
(\n) # \n matches all platforms' ends of lines
}{ #
sprintf("%%%02x", ord($1)) # replacement hex code
}xeg;
if ($anvl_mode eq 'ANVLS') {
$s =~ s/\|/%7c/g; # URL-encode all vertical bars (%vb)
$s =~ s/;/%3b/g; # URL-encode all semi-colons (%sc)
# XXX what about others, such as (:...) (=...)
};
lib/File/OM.pm view on Meta::CPAN
# PSV names used only in header line
my ($self, $s) = (shift, shift);
defined($s) or return '';
# xxx document how we don't trim, but encode spaces
# xxxxxxx and then encode!!
#$s =~ s/^\s+//;
#$s =~ s/\s+$//; # trim both ends
#$s =~ s/\s+/ /g; # squeeze multiple \s to one space
$s =~ s/%/%%/g; # to preserve literal %, double it
# yyy must be decoded by receiver
$s =~ s/\|/%7c/g; # URL-encode all colons
$s =~ s/\n/%0a/g; # URL-encode all newlines
return $s;
}
sub value_encode { # OM::PSV
my ($self, $s) = (shift, shift);
defined($s) or return '';
# xxx document how we don't trim, but encode spaces
# xxxxxxx and then encode!!
#$s =~ s/^\s+//;
#$s =~ s/\s+$//; # trim both ends
#$s =~ s/\s+/ /g; # squeeze multiple \s to one space
$s =~ s/%/%%/g; # to preserve literal %, double it
# yyy must be decoded by receiver
$s =~ s/\|/%7c/g; # URL-encode all colons
$s =~ s/\n/%0a/g; # URL-encode all newlines
return $s;
}
sub comment_encode { # OM::PSV
# in PSV this would be a pseudo-comment
my ($self, $s) = (shift, shift);
defined($s) or return '';
$s =~ s/%/%%/g; # to preserve literal %, double it
# yyy must be decoded by receiver
$s =~ s/\|/%7c/g; # URL-encode all colons
$s =~ s/\n/%0a/g; # URL-encode all newlines
return $s;
}
package File::OM::Turtle;
our @ISA = ('File::OM');
lib/File/OM.pm view on Meta::CPAN
Smith, Jo
home: 555-1234
work: 555-9876
in which case they contain the line number and value, respectively. Array
element 1 always contains a string naming the format of the input, such
as, "ANVL", "JSON", "XML", etc.
The remaining triples are free form except that the values will have been
drawn from the original format and possibly decoded. The first item
("lineno") in each remaining triple is a number followed by a letter,
such as "34:" or "6#". The number indicates the line number (or octet
offset, depending on the origin format) of the start of the element. The
letter is either ':' to indicate a real element or '#' to indicate a
comment; if the latter, the element name has no defined meaning and the
comment is contained in the value. To output an element as a comment
without regard to line number, give $lineno as "#".
B<OM> presents an object oriented interface. The object constructor
takes a format argument and returns C<undef> if the format is unknown.
( run in 0.426 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )