User:AnomieBOT/source/tasks/SourceUploader/Pod.pm: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: General: * Have the bot script watch for changes and automatically re-exec itself. SourceUploader: * Change things around so task metadata is stored with the task.
 
AnomieBOT (talk | contribs)
Updating published sources: TagDater: * When check_page2 was split from check_page for unit testing purposes, some function calls weren't updated properly so check_page() was getting called with wrong arguments. General: * Apparently @_ holds implicit...
 
(8 intermediate revisions by the same user not shown)
Line 1:
<sourcesyntaxhighlight lang="perl">
package tasks::SourceUploader::Pod;
 
use utf8;
use strict;
use Pod::Simple;
Line 12 ⟶ 13:
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->encoding( 'utf8' ) if $self->can('encoding');
$self->accept_targets('*');
$self->{'stack'}=[];
Line 32 ⟶ 34:
target=>$_[1]{'target'},
para=>[],
line=>exists($_[1]{'line_number'})?$_[1]{'line_number'}: // $self->line_count
};
} elsif($_[0] eq 'Data'){
Line 46 ⟶ 48:
$s=$s->[$#$s]{'para'};
return unless @$s;
my $txt = $_[0]=~s/\r\n/\n/g;
$_[0]txt=~s/\r\n/\n/g;
$txt=~s->[$#$s].=$_[0]/\r/\n/g;
$s->[$#$s].=$txt;
}
 
Line 73 ⟶ 76:
s/^\s*|\s*$//g;
if(!/^(\S+?):\s*(.*)$/){
$self->whinedie($line, "Bad header line in metadata block at $line");
next;
}
$metadata{lcif(substr($1,0,1)}=$2; eq '+'){
$metadata{lc($1)}=[] unless exists($metadata{lc($1)});
push @{$metadata{lc($1)}}, $2;
} else {
$metadata{lc($1)}=$2;
}
}
my $text=join("\n\n", @para);
$text=~s/([^\n])\n(?=[a-zA-Z0-9< ])/$1 /g; # unwrap lines
$metadata{'*'}=$text;
$self->{'metadata'}=\%metadata;
Line 102 ⟶ 110:
my $text=join("\n\n", @{$_[0]});
$text=~s/\n(?=[a-zA-Z0-9])/ /g; # unwrap lines
print {$self->output_fh} "\x7b\x7bombox|type=customcontent|style=border:1px solid #b22222|image=\x5b\x5bImage:Ambox warning pn.svg|40px\x5d\x5d|text=$text\x7d\x7d\n";
}
 
1;
 
</syntaxhighlight>
</source>