From: Gavin Carr Date: Thu, 27 Dec 2007 11:01:30 +0000 (+0000) Subject: Convert remaining gavinc plugins to %config versions. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=1c2ded0e43a7f208694862d89c38f8c83688ff61;p=matthijs%2Fupstream%2Fblosxom-plugins.git Convert remaining gavinc plugins to %config versions. --- diff --git a/gavinc/metamail b/gavinc/metamail index 3ae65df..984f7f7 100644 --- a/gavinc/metamail +++ b/gavinc/metamail @@ -1,6 +1,6 @@ # Blosxom Plugin: metamail # Author(s): Gavin Carr -# Version: 0.001000 +# Version: 0.002000 # Documentation: 'perldoc metamail' # Requires: metaclear # Follows: metaclear @@ -8,19 +8,22 @@ package metamail; use strict; +use vars qw(%config); #use Blosxom::Debug debug_level => 1; # --- Configurable variables ----- +%config = (); + # Headers to consider titles -my @title_headers = qw(Title Subject); +$config{title_headers} = [ qw(Title Subject) ]; # Headers to keep in the body (required by later plugins, for instance) -my @keep_in_body_headers = qw(Tags); +$config{keep_in_body_headers} = qw(Tags); # Whether to unfold (join) multi-line headers -my $unfold_headers = 1; +$config{unfold_headers} = 1; # -------------------------------- # __END_CONFIG__ @@ -44,13 +47,13 @@ sub story { } # For backwards compatibility, assume a header without a : is a title else { - $key = @title_headers[0] || 'Title'; + $key = $config{title_headers}->[0] || 'Title'; $value = $header; } chomp $value; # Unfold - $value =~ s/\n //g if $unfold_headers; + $value =~ s/\n //g if $config{unfold_headers}; # Cache header $header{$key} = $value; @@ -68,12 +71,12 @@ sub story { # Update $$title_ref to the first title_header we can find $$title_ref = ''; - for (@title_headers) { + for (@{$config{title_headers}}) { $$title_ref = $header{$_} and last if $header{$_}; } # Update body_ref - if (my @keep_headers = grep { defined $header{$_} } @keep_in_body_headers) { + if (my @keep_headers = grep { defined $header{$_} } @{$config{keep_in_body_headers}}) { $$body_ref = join("\n", map { "$_: $header{$_}" } @keep_headers) . "\n" . $body; } else { @@ -123,7 +126,7 @@ metamail will create the following %blosxom::meta entries: For backwards compatibility purposes, L will treat any header not containing a colon (which is typically the first line title) as the -'Title' of the post, and store it with the first key in @title_headers +'Title' of the post, and store it with the first key in 'title_headers' (default is 'Title'). L supports the title being anywhere in the headers, and will report it properly to blosxom, but any plugins that look directly at the post file may still expect the title diff --git a/gavinc/storydate b/gavinc/storydate index 78c2df1..f8c7246 100644 --- a/gavinc/storydate +++ b/gavinc/storydate @@ -2,13 +2,14 @@ # Author(s): Gavin Carr # (based on work by Frank Hecker # and Bob Schumaker ) -# Version: 0.002000 +# Version: 0.003000 # Documentation: See the bottom of this file or type: perldoc storydate package storydate; use strict; +use vars qw(%config); use File::stat; # Uncomment next line to enable debug output (don't uncomment debug() lines) @@ -16,8 +17,10 @@ use File::stat; # --- Configuration variables ----- +%config = (); + # Perl modules to use for strftime, in search order -my @strftime_modules = qw(Time::Piece Date::Format POSIX); +$config{strftime_modules} = [ qw(Time::Piece Date::Format POSIX) ]; # --------------------------------- # __END_CONFIG__ @@ -128,7 +131,7 @@ sub format_date { return $date; } -# strftime wrapper, using the first strftime() it finds in @strftime_modules +# strftime wrapper, using the first strftime() it finds in 'strftime_modules' my %cache = (); my $strftime_module = ''; sub strftime { @@ -145,7 +148,7 @@ sub strftime { # Search for a strftime module, and load if (! $strftime_module) { - for my $module (@strftime_modules) { + for my $module (@{$config{strftime_modules}}) { if (eval "require $module") { $strftime_module = $module; # debug(2, "strftime_module: $strftime_module"); diff --git a/gavinc/storytags b/gavinc/storytags index 1665dbf..e1426a8 100644 --- a/gavinc/storytags +++ b/gavinc/storytags @@ -1,6 +1,6 @@ # Blosxom Plugin: storytags # Author(s): Gavin Carr -# Version: 0.002000 +# Version: 0.003000 # Documentation: See the bottom of this file or type: perldoc storytags # Requires: tags # Follows: tags @@ -12,13 +12,15 @@ use strict; # Uncomment next line to enable debug output (don't uncomment debug() lines) #use Blosxom::Debug debug_level => 1; -use vars qw($taglist @taglist); +use vars qw(%config $taglist @taglist); # --- Configuration variables ----- +%config = (); + # Formatting strings -my $prefix = 'Tags: '; -my $suffix = '. '; +$config{prefix} = 'Tags: '; +$config{suffix} = '. '; # --------------------------------- # __END_CONFIG__ @@ -48,12 +50,12 @@ sub story { sub _format_taglist { my ($tags) = @_; return '' unless @$tags; - return $prefix + return $config{prefix} . join(', ', map { qq() } @$tags ) - . $suffix; + . $config{suffix}; } 1; @@ -70,12 +72,12 @@ and @storytags::taglist array of tags L is a blosxom plugin to format a per-story $storytags::taglist string, and a @storytags::taglist array of tags. The $taglist is a comma-separated list of the tags defined for the story, prefixed by -$storytags::prefix, and suffixed by $storytags::suffix. If no tags are +$config{prefix}, and suffixed by $config{suffix}. If no tags are defined, then $taglist will be the empty string '' (i.e. no prefix and suffix are added). @taglist is a simple array of the tags for the story, and an empty array if none are set. -The default values for $prefix and $suffix are 'Tags: ' and '. ' +The default values for 'prefix' and 'suffix' are 'Tags: ' and '. ' respectively, so a typical $taglist might look like: Tags: dogs, cats, pets. diff --git a/gavinc/tags b/gavinc/tags index 5c5d813..644239e 100644 --- a/gavinc/tags +++ b/gavinc/tags @@ -1,6 +1,6 @@ # Blosxom Plugin: tags # Author(s): Gavin Carr -# Version: 0.001000 +# Version: 0.002000 # Documentation: See the bottom of this file or type: perldoc tags package tags; @@ -11,18 +11,20 @@ use File::stat; # Uncomment next line to enable debug output (don't uncomment debug() lines) #use Blosxom::Debug debug_level => 2; -use vars qw($tagroot $tag_cache $tag_entries $tag_counts); +use vars qw(%config $tag_cache $tag_entries $tag_counts); # --- Configuration variables ----- +%config = (); + # What path prefix is used for tag-based queries? -$tagroot = "/tags"; +$config{tagroot} = "/tags"; # What story header to you use for your tags? -my $tag_header = 'Tags'; +$config{tag_header} = 'Tags'; # Where is our $tag_cache file? -my $tag_cache_file = "$blosxom::plugin_state_dir/tag_cache"; +$config{tag_cache_file} = "$blosxom::plugin_state_dir/tag_cache"; # --------------------------------- # __END_CONFIG__ @@ -37,8 +39,8 @@ my $path_tags_op; sub start { # Load tag_cache - if (-f $tag_cache_file) { - my $fh = FileHandle->new( $tag_cache_file, 'r' ) + if (-f $config{tag_cache_file}) { + my $fh = FileHandle->new( $config{tag_cache_file}, 'r' ) or warn "[tags] cannot open cache: $!"; { local $/ = undef; @@ -55,7 +57,7 @@ sub entries { my $path_info = "/$blosxom::path_info"; # debug(3, "entries, path_info $path_info"); - if ($path_info =~ m!^$tagroot/(.*)!) { + if ($path_info =~ m!^$config{tagroot}/(.*)!) { $blosxom::flavour = ''; my $taglist = $1; # debug(3, "entries, path_info matches tagroot (taglist $taglist)"); @@ -76,7 +78,7 @@ sub entries { @path_tags = split /\s*,\s*/, $taglist; $path_tags_op = ','; } - # If $path_info matches $tagroot it's a virtual path, so reset + # If $path_info matches tagroot it's a virtual path, so reset $blosxom::path_info = ''; $blosxom::flavour ||= $blosxom::default_flavour; } @@ -133,7 +135,7 @@ sub story { } # mtime has changed (or story is new) - compare old and new tagsets - my $tags_new = $blosxom::meta{$tag_header}; + my $tags_new = $blosxom::meta{$config{tag_header}}; my $tags_old = $tag_cache->{"$path/$filename"}->{tags}; # debug(2, "tags_new: $tags_new, tags_old: $tags_old"); @@ -160,9 +162,9 @@ sub last { } } - # Save tag caches back to $tag_cache_file - my $fh = FileHandle->new( $tag_cache_file, 'w' ) - or warn "[tags] cannot open cache '$tag_cache_file': $!" + # Save tag caches back to $config{tag_cache_file} + my $fh = FileHandle->new( $config{tag_cache_file}, 'w' ) + or warn "[tags] cannot open cache '$config{tag_cache_file}': $!" and return 0; print $fh Data::Dumper->Dump([ $tag_cache, $tag_entries, $tag_counts ], [ qw(tag_cache tag_entries tag_counts) ]); @@ -184,9 +186,9 @@ and allow tag-based filtering L is a blosxom plugin to read tags from story files, maintain a tag cache, and allow tag-based filtering. -Tags are defined in a comma-separated list in a $tag_header header at the -beginning of a blosxom post, with $tag_header defaulting to 'Tags'. So for -example, your post might look like: +Tags are defined in a comma-separated list in a $config{tag_header} header +at the beginning of a blosxom post, with $tag_header defaulting to 'Tags'. +So for example, your post might look like: My Post Title Tags: dogs, cats, pets @@ -194,16 +196,16 @@ example, your post might look like: Post text goes here ... L uses the L plugin to parse story headers, and stores -the tags in a cache (in $tag_cache_file, which defaults to +the tags in a cache (in $config{tag_cache_file}, which defaults to $blosxom::plugin_state_dir/tag_cache). The tag cache is only updated when the mtime of the story file changes, so L should perform pretty well. L also supports tag-based filtering. If the blosxom $path_info -begins with $tagroot ('/tags', by default, e.g. '/tags/dogs'), then -L filters the entries list to include only posts with the +begins with $config{tagroot} ('/tags', by default, e.g. '/tags/dogs'), +then L filters the entries list to include only posts with the specified tag. The following syntaxes are supported (assuming the -default '/tags' for $tagroot): +default '/tags' for 'tagroot'): =over 4