On Mon, 17 Sep 2001, Doug MacEachern wrote:
> On Tue, 18 Sep 2001, Stas Bekman wrote:
>
> > +use constant WARN_STYLE_NONE => 0;
> > +use constant WARN_STYLE_PERL => 1;
> > +use constant WARN_STYLE_C => 2;
>
> one thing to consider though, ModPerl::Code has
> noedit_warning_{c,hash} and this comment:
>
> #this is named hash after the `#' character
> #rather than named perl, since #comments are used
> #non-Perl files, e.g. Makefile, typemap, etc.
>
> many of the genfile() calls are generating files that are not Perl code.
> if you look at your patch, there's genfile called for mime.types, *.conf,
> .gdb*, etc. how about this, rather than a style argument to genfile(),
> let genfile figure it out for you based on the file extension.
>
> something like:
>
> my %warnings = (
> html => sub {
> "<!-- @_ -->"
> },
> c => sub {
> "/* @_ */"
> },
> default => sub {
> my $string = join '', @_;
> $string =~ s/^/\#/g;
> $string;
> },
> );
> $warnings{h} = $warnings{c};
In any case here is something that I wrote (untested, just the concept):
my %warn_style =
(
html => sub { "<!-- @_ -->" },
c => sub { "/* @_ */" },
default => sub { join '', map {s/^/\#/g} @_; },
);
my %file_ext =
(
map({$_ => 'html'}, qw(htm html)),
map({$_ => 'c'}, qw(c h)),
);
sub warn_style_sub {
my ($self, $filename) = @_;
my $ext = (File::Basename::fileparse($filename, '\..*'))[3] || '';
$ext =~ s/^\.(.*)/"\L$1"/e;
return $warn_style{ $file_ext{$ext} || 'default' } || sub {};
}
sub genwarning {
my($self, $filename) = @_;
return unless $type;
my $warning = "#WARNING: this file is generated, do not edit\n" .
calls_trace();
return warn_style_sub($filename)->($warning);
}
hope that warn_style_sub is not too cryptic.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]