# File lib/puppet/parser/parser_support.rb, line 278
278:     def newclass(name, options = {})
279:         name = name.downcase
280: 
281:         if @loaded_code.definition(name)
282:             raise Puppet::ParseError, "Cannot redefine class %s as a definition" % name
283:         end
284:         code = options[:code]
285:         parent = options[:parent]
286:         doc = options[:doc]
287: 
288:         # If the class is already defined, then add code to it.
289:         if other = @loaded_code.hostclass(name) || @loaded_code.definition(name)
290:             # Make sure the parents match
291:             if parent and other.parentclass and (parent != other.parentclass)
292:                 error("Class %s is already defined at %s:%s; cannot redefine" % [name, other.file, other.line])
293:             end
294: 
295:             # This might be dangerous...
296:             if parent and ! other.parentclass
297:                 other.parentclass = parent
298:             end
299: 
300:             # This might just be an empty, stub class.
301:             if code
302:                 tmp = name
303:                 if tmp == ""
304:                     tmp = "main"
305:                 end
306: 
307:                 Puppet.debug addcontext("Adding code to %s" % tmp)
308:                 # Else, add our code to it.
309:                 if other.code and code
310:                     # promote if neededcodes to ASTArray so that we can append code
311:                     # ASTArray knows how to evaluate its members.
312:                     other.code = ast AST::ASTArray, :children => [other.code] unless other.code.is_a?(AST::ASTArray)
313:                     code = ast AST::ASTArray, :children => [code] unless code.is_a?(AST::ASTArray)
314:                     other.code.children += code.children
315:                 else
316:                     other.code ||= code
317:                 end
318:             end
319: 
320:             if other.doc and doc
321:                 other.doc += doc
322:             else
323:                 other.doc ||= doc
324:             end
325:         else
326:             # Define it anew.
327:             # Note we're doing something somewhat weird here -- we're setting
328:             # the class's namespace to its fully qualified name.  This means
329:             # anything inside that class starts looking in that namespace first.
330:             args = {:namespace => name, :classname => name, :parser => self}
331:             args[:code] = code if code
332:             args[:parentclass] = parent if parent
333:             args[:doc] = doc
334:             args[:line] = options[:line]
335: 
336:             @loaded_code.add_hostclass(name, ast(AST::HostClass, args))
337:         end
338: 
339:         return @loaded_code.hostclass(name)
340:     end