Tripletail
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
ext/Tripletail-HtmlFilter/HtmlFilter.pm view on Meta::CPAN
use Tripletail;
use DynaLoader;
use base 'DynaLoader';
our @XSUBS = qw(next _next_elem Element::parse Element::attr);
our $XS_LOADERROR;
Tripletail::HtmlFilter->my_bootstrap($Tripletail::XS_VERSION);
use constant {
# 注æ: ãããå¤æ´ããæ㯠XS å´ãä¿®æ£ããäºã
INTEREST => 0,
TRACK => 1,
FILTER_TEXT => 2,
FILTER_COMMENT => 3,
CONTEXT => 4,
HTML => 5,
OUTPUT => 6,
};
my %_MATCHER_CACHE;
sub my_bootstrap
{
my $pkg = shift;
if( !$PURE_PERL )
{
local ($@);
eval
{
local($SIG{__DIE__}) = 'DEFAULT';
$pkg->SUPER::bootstrap(@_);
};
$XS_LOADERROR = $@;
}else
{
$XS_LOADERROR = 'disabled';
}
do
{
no strict 'refs';
#$err and chomp $err;
#warn "warning: $err";
foreach my $name (@XSUBS)
{
my $xsub = __PACKAGE__.'::'.$name;
if( !defined(&$xsub) )
{
(my $ppsub = $xsub) =~ s/(\w+)$/_$1_pp/;
*$xsub = \&$ppsub;
}
}
}
}
1;
sub _new {
my $class = shift;
my $opts = { @_ };
my $this = bless [] => $class;
$this->[INTEREST] = $opts->{interest};
$this->[TRACK] = $opts->{track};
$this->[FILTER_TEXT] = $opts->{filter_text};
$this->[FILTER_COMMENT] = $opts->{filter_comment};
$this->[CONTEXT] = Tripletail::HtmlFilter::Context->_new;
$this->[HTML] = undef; # æåå
$this->[OUTPUT] = []; # Tripletail::HtmlFilter::{Element,Text,Comment}
# interest, trackã«æ¸¡ãããæ£è¦è¡¨ç¾ã¯ãã®æç¹ã§ CODE ã«ã³ã³ãã¤ã«ãã¦ããã
if ($this->[INTEREST]) {
$this->[INTEREST] = $this->_compile_matcher($this->[INTEREST]);
}
if ($this->[TRACK]) {
$this->[TRACK] = $this->_compile_matcher($this->[TRACK]);
}
$this;
}
sub set {
my $this = shift;
my $html = shift;
if (not defined $html) {
die __PACKAGE__."#set: ARG[1] is not defined.\n";
}
elsif (ref $html) {
die __PACKAGE__."#set: ARG[1] is a Ref.\n";
}
#@{$this->[HTML]} = split m/(<.+?>)/s, $html;
# âã§ã¯ã<!-- <hoge> -->ãæ£ãã解æã§ããªããçé¢ç®ã«ãã¼ãºããå¿
è¦ããã
# ããããperlã§çé¢ç®ã«ãã¼ã¶ãæ¸ãã®ã¯é常ã«é¢åãªã®ã§æ£è¦è¡¨ç¾ã§èª¤éåã
# NB: ä»ã«ããæ£ãã解æã§ããªããã¿ã¼ã³ãåå¨ãããã
@{$this->[HTML]} = split m/((?:<!--.*?-->)|(?:<.+?>))/s, $html;
@{$this->[OUTPUT]} = ();
$this;
}
sub toStr {
my $this = shift;
$this->[CONTEXT]->_flush($this); # æªç¢ºå®ã®é¨åã確å®ãã
join('', map {ref($_)?$_->toStr:$_} @{$this->[OUTPUT]});
}
sub _compile_matcher {
my $this = shift;
my $regexes = shift;
my $joined = join('', @$regexes);
if (my $cached = $_MATCHER_CACHE{$joined}) {
return $cached;
}
my $ret = [];
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.915 second using v1.00-cache-2.02-grep-82fe00e-cpan-48ebf85a1963 )