3 # Script to convert blosxom plugin config variables to globals,
4 # for setting via 'blosxom.conf' or 'config' or 'prefs'
13 getopts('nq', \%opts);
17 my $dir = shift @ARGV || '*';
18 for my $pname ( glob $dir ) {
19 next unless -f $pname;
20 my $ph = IO::File->new( $pname, 'r' )
21 or warn "Cannot open plugin '$pname' for read: $!" and next;
29 next unless $plugin =~ m/__END_CONFIG__/;
30 print "Updating $pname ...\n" unless $quiet;
32 my ($pre, $post) = split m/__END_CONFIG__/, $plugin, 2;
37 while ($modified =~ m/^(\s*#\s*)?my\s+((\$\w+)\s*=)/m) {
39 $modified =~ s/^(\s*#\s*)?my\s+((\$\w+)\s*=)/$1$2/m;
41 # Add a 'use vars' for lexicals if in strict mode
43 @lexicals = map { $seen{$_}++ ? () : $_ } @lexicals;
44 my $lexicals = join ' ', @lexicals;
45 $modified =~ s/^(use\s+strict\b[^\n]+\n)/$1use vars qw($lexicals);\n/m;
47 # Add unless defined fragments to all config variables
48 $modified =~ s/\G(.*?^#?\s*([\$\@%]\w+)\s*=[^;]+);/$1 unless defined $2;/msg;
50 # print "modified:\n\n$modified\n\n";
52 next if $modified eq $pre;
54 # Reconstitute and write out
55 $plugin = $modified . "__END_CONFIG__" . $post;
56 $ph = IO::File->new( "$pname.tmp", 'w' )
57 or die "Cannot open plugin '$pname.tmp' for write: $!";
59 or die "Cannot write to plugin '$pname.tmp': $!";
61 or die "Cannot close plugin '$pname.tmp': $!";
62 move "$pname.tmp", $pname
63 or die "Cannot move plugin '$pname.tmp' to '$pname': $!";
66 print "Done.\n" unless $quiet;