def items=(str)
raise ArgumentError, "template #{str.inspect} should be a String" unless str.kind_of?(String)
items = str.strip.split(/\]?\s+\[?|\]?$/).collect { |c|
if /^(:|\*)(\w+)(.*)/ =~ c
sym = ($1 == ':' ) ? $2.intern : "*#{$2}".intern
if $3.empty?
sym
else
[sym, $3]
end
else
c
end
}.flatten
@items = items
raise ArgumentError, "Illegal template -- first component cannot be dynamic: #{str.inspect}" if @items.first.kind_of? Symbol
raise ArgumentError, "Illegal template -- first component cannot be optional: #{str.inspect}" if @items.first =~ /\[|\]/
@items.inject({}) do |seen, item|
if item.kind_of? Symbol
it = item.to_s.sub(/^\*/,"").intern
raise ArgumentError, "Illegal template -- duplicate item #{it} in #{str.inspect}" if seen.key? it
seen[it] = true
end
seen
end
end