(file) Return to Attrs.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / twiki / lib / TWiki / Plugins / CommentPlugin

 1 rizwank 1.1 #
 2             # Copyright (C) Motorola 2001 - All rights reserved
 3             #
 4             # TWiki extension that adds tags for the generation of tables of contents.
 5             #
 6             # This program is free software; you can redistribute it and/or
 7             # modify it under the terms of the GNU General Public License
 8             # as published by the Free Software Foundation; either version 2
 9             # of the License, or (at your option) any later version.
10             #
11             # This program is distributed in the hope that it will be useful,
12             # but WITHOUT ANY WARRANTY; without even the implied warranty of
13             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14             # GNU General Public License for more details, published at 
15             # http://www.gnu.org/copyleft/gpl.html
16             #
17             use strict;
18             use integer;
19             
20             # Class of attribute sets
21             # An attribute set is a hash containing an entry for each parameter. The
22 rizwank 1.1 # default parameter (quoted string) is named "__default__" in the hash.
23             { package TWiki::Plugins::CommentPlugin::Attrs;
24             
25               # Parse a standard attribute string containing name=value pairs. The
26               # value may be a word or a quoted string (no escapes!)
27               sub new {
28                 my ( $class, $string ) = @_;
29                 my $this = {};
30             
31                 if ( defined( $string ) ) {
32                   # name="value" pairs
33                   while ( $string =~ s/([a-z]\w+)\s*=\s*\"([^\"]*)\"//io ) {
34                     $this->{$1} = $2;
35                   }
36                   # name=value pairs
37                   while ( $string =~ s/([a-z]\w+)\s*=\s*([^\s,\}]*)//io ) {
38                     $this->{$1} = $2;
39                   }
40                   # simple quoted value with no name; only one allowed;
41                   # sets the key "__default__"
42                   if ( $string =~ s/\"(.*?)\"//o ) {
43 rizwank 1.1         $this->{"__default__"} = $1;
44                   }
45                   # simple name with no value (boolean)
46                   while ( $string =~ s/([a-z]\w+)\b//o ) {
47                     $this->{$1} = "on";
48                   }
49                 }
50                 return bless( $this, $class );
51               }
52             
53               # PUBLIC Get an attr value; return undef if not set
54               sub get {
55                 my ( $this, $attr ) = @_;
56                 return $this->{$attr};
57               }
58             
59               # PUBLIC remove an attr value from the hash, return old value
60               sub remove {
61                 my ( $this, $attr ) = @_;
62                 my $val = $this->{$attr};
63                 delete( $this->{$attr} ) if ( $val );
64 rizwank 1.1     return $val;
65               }
66             
67               # PUBLIC generate a printed form for the hash, using standard
68               # attribute syntax.
69               sub toString {
70                 my $this = shift;
71                 my $key;
72                 my $ss = "";
73                 foreach $key ( keys %$this ) {
74                   if ( $key eq "__default__" ) {
75             	$ss = " \"" . $this->{$key} . "\"$ss";
76                   } else {
77             	$ss .= " $key=\"" . $this->{$key} . "\"";
78                   }
79                 }
80                 return "{$ss }";
81               }
82             
83             } # end of class Attrs
84             
85 rizwank 1.1 1;

Rizwan Kassim
Powered by
ViewCVS 0.9.2