/usr/share/perl5/PPI/HTML/Fragment.pm is in libppi-html-perl 1.08-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | package PPI::HTML::Fragment;
# A HTML fragment object is a small object that contains a string due to
# become HTML content, and a simple rule for it's display, such as a class
# name.
use strict;
use vars qw{$VERSION};
BEGIN {
$VERSION = '1.08';
}
#####################################################################
# Constructor and Accessors
sub new {
my $class = ref $_[0] ? ref shift : shift;
my $string = defined $_[0] ? shift : return undef;
my $css = shift or return undef;
# Create the basic object
my $self = bless {
string => $string,
css => $css,
}, $class;
$self;
}
sub string { $_[0]->{string} }
sub css { $_[0]->{css} }
#####################################################################
# Main Methods
# Does the segment end with a newline?
sub ends_line { $_[0]->string =~ /\n$/ }
# Render to HTML
sub html {
my $self = shift;
my $html = $self->_escape( $self->string );
return $html unless $self->css;
$self->_tagpair( 'span', { class => $self->css }, $html );
}
sub concat {
my $self = shift;
my $string = defined $_[0] ? shift : return undef;
$self->{string} .= $string;
1;
}
sub clear {
my $self = shift;
delete $self->{css};
1;
}
#####################################################################
# Support Methods
# Embedding some HTML stuff until I find a suitably lightweight dependency
sub _escape {
my $html = defined $_[1] ? "$_[1]" : return '';
$html =~ s/&/&/g;
$html =~ s/</</g;
$html =~ s/>/>/g;
$html =~ s/\"/"/g;
$html =~ s/(\015{1,2}\012|\015|\012)/<br>\n/g;
$html;
}
sub _tagpair {
my $class = shift;
my $tag = shift or return undef;
my %attr = ref $_[0] eq 'HASH' ? %{shift()} : ();
my $start = join( ' ', $tag,
map { defined $attr{$_} ? qq($_="$attr{$_}") : "$_" }
sort keys %attr );
"<$start>" . join('', @_) . "</$tag>";
}
1;
|