Difference: TWikiAttrsDotPm (1 vs. 3)

Revision 322 Jan 2008 - Main.TWikiContributor

Line: 1 to 1
 

Package TWiki::Attrs

Class of attribute sets, designed for parsing and storing attribute values

Changed:
<
<
from a TWiki tag e.g. %TAG{fred='bad' "sad" joe="mad"}%
>
>
from a TWiki tag e.g. %TAG{"joe" fred="bad" joe="mad"}%
 
Changed:
<
<
An attribute set is a map containing an entry for each parameter. The default parameter (unnamed quoted string) is named _DEFAULT in the map.
>
>
An attribute set is a hash containing an entry for each parameter. The default parameter (unnamed quoted string) is named _DEFAULT in the hash.
  Attributes declared later in the string will override those of the same name defined earlier. The one exception to this is the _DEFAULT key, where
Changed:
<
<
the first instance of a setting is always taken.
>
>
the first instance is always taken.
 
Changed:
<
<
As well as standard TWiki syntax (parameter values double-quoted) it also parses single-quoted values, unquoted spaceless values, spaces around the =, and commas as well as spaces separating values, though none of these alternatives is advertised in documentation and the extended syntax can be turned off by passing the 'strict' parameter
>
>
As well as the default TWiki syntax (parameter values double-quoted) this class also parses single-quoted values, unquoted spaceless values, spaces around the =, and commas as well as spaces separating values. The extended syntax has to be enabled by passing the $friendly parameter
 to new.
Deleted:
<
<
This class replaces the old TWiki::extractNameValuePair and TWiki::extractParameters.
 
Line: 61 to 57
 

ObjectMethod remove ($key) -> $value

Changed:
<
<
$key Attribute to remove
>
>
  • $key - Attribute to remove
 Remove an attr value from the map, return old value. After a call to remove the attribute is no longer defined.
Line: 69 to 65
 

ObjectMethod stringify () -> $string

Changed:
<
<
Generate a printed form for the map, using standard
>
>
Generate a printed form for the map, using strict
 attribute syntax, with only the single-quote extension syntax observed (no {} brackets, though).
Deleted:
<
<

StaticMethod extractValue () -> $string

Legacy support, formerly known as extractNameValuePair. This static method uses context information to determine how a value string is to be parsed. For example, if you have an attribute string like this:

"abc def="ghi" jkl" def="qqq"

then call extractValue( "def" ), it will return "ghi".

ObjectMethod get ($key) -> $value

$key Attribute to get
Get an attr value from the map.

Synonymous with $attrs->{$key}. Retained mainly for compatibility with the old AttrsContrib? .

Revision 216 Jan 2007 - Main.TWikiContributor

Revision 101 Feb 2006 - Main.TWikiContributor

Line: 1 to 1
Added:
>
>

Package TWiki::Attrs

Class of attribute sets, designed for parsing and storing attribute values from a TWiki tag e.g. %TAG{fred='bad' "sad" joe="mad"}%

An attribute set is a map containing an entry for each parameter. The default parameter (unnamed quoted string) is named _DEFAULT in the map.

Attributes declared later in the string will override those of the same name defined earlier. The one exception to this is the _DEFAULT key, where the first instance of a setting is always taken.

As well as standard TWiki syntax (parameter values double-quoted) it also parses single-quoted values, unquoted spaceless values, spaces around the =, and commas as well as spaces separating values, though none of these alternatives is advertised in documentation and the extended syntax can be turned off by passing the 'strict' parameter to new.

This class replaces the old TWiki::extractNameValuePair and TWiki::extractParameters.

ClassMethod new ($string,$friendly)=>\%attrsObjectRef

  • $string - String containing attribute specification
  • $friendly - if true, the parse will be according to the extended syntax pioneered by the original Contrib::Attrs. Otherwise it will be strict as per traditional TWiki syntax.

Parse a standard attribute string containing name=value pairs and create a new attributes object. The value may be a word or a quoted string. If there is an error during parsing, the parse will complete but $attrs->{_ERROR} will be set in the new object. $attrs->{_RAW} will always contain the full unprocessed $string.

Extended syntax example:

my $attrs = new TWiki::Attrs('the="time \\"has come", "the walrus" said to=speak of=\'many \\'things\', 1);
In this example:
  • the will be time "has come
  • __default__ will be the walrus
  • said will be on
  • to will be speak
  • of will be many 'things

Only " and ' are escaped.

Traditional syntax is as old TWiki, except that the whole string is parsed (the old parser would only recognise default values in position 1, nowhere else)

ObjectMethod isEmpty () -> boolean

Return false if attribute set is not empty.

ObjectMethod remove ($key) -> $value

$key Attribute to remove
Remove an attr value from the map, return old value. After a call to remove the attribute is no longer defined.

ObjectMethod stringify () -> $string

Generate a printed form for the map, using standard attribute syntax, with only the single-quote extension syntax observed (no {} brackets, though).

StaticMethod extractValue () -> $string

Legacy support, formerly known as extractNameValuePair. This static method uses context information to determine how a value string is to be parsed. For example, if you have an attribute string like this:

"abc def="ghi" jkl" def="qqq"

then call extractValue( "def" ), it will return "ghi".

ObjectMethod get ($key) -> $value

$key Attribute to get
Get an attr value from the map.

Synonymous with $attrs->{$key}. Retained mainly for compatibility with the old AttrsContrib? .

 
This site is powered by the TWiki collaboration platformCopyright � by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback
Note: Please contribute updates to this topic on TWiki.org at TWiki:TWiki.TWikiAttrsDotPm