Forum OpenACS Development: Re: OpenACS, XoTcl, and ActiveRecord

Collapse
Posted by Benjamin Bytheway on
Lars,

This looks like a great idea.  During the past few months I've also wondered if XOTcl and OpenACS might not make a good match.

The reason [AcsObject table_name] doesn't work is because you are getting the name of the class (AcsObject is of class ActiveRecord) instead of the name of the object itself.  Your demo will work if you change [my info class] to [self] in the table_name proc.

ActiveRecord instproc table_name {} {
    # Transforms AcsObject -> acs_object
    set table_name [lindex [split [self] ::] end]
    regsub {([a-z])([A-Z])} $table_name {\1_\2} table_name
    set table_name [string tolower $table_name]
    return $table_name
}

Collapse
Posted by Tom Jackson on
set table_name [lindex [split [self] ::] end]

Did split change? Split uses each char to do the split. If the separation chars are "::" as in a namespace, use namespace commands:

set parent [namespace qualifiers [self]]
set child  [namespace tail [self]]

The namespace doesn't need to exist, just a string of the correct form.

How does this all relate to persistence, is each record stored as an object? How does it persist in OpenACS?

Collapse
Posted by Steve Manning on
Quoting from the TCL man:

"[split] Returns a list created by splitting string at each character that is in the splitChars argument. Each element of the result list will consist of the characters from string that lie between instances of the characters in splitChars. Empty list elements will be generated if string contains adjacent characters in splitChars, or if the first or last character of string is in splitChars. If splitChars is an empty string then each character of string becomes a separate element of the result list. SplitChars defaults to the standard white-space characters."

Therefore if I'm not mistaken:

[split [self] ::]

will attempt to split self by ':' and ':' rather than '::' which will produce an empty string between each element e.g

set self "mytcl::namespace::isgroovy"
split $self ::

gives a list of 5 elements:

mytcl {} namespace {} isgroovy

rather than a list of three elements:

mytcl namespace isgroovy

I get round this by regsubbing a safe chr inplace of the string then splitting on that chr.

I don't know if that is the desired effects - I'm just poking my nose in.

    - Steve

Collapse
Posted by Tom Jackson on

If the string returned by [self] is a namespace, or qualified procedure name, you really should use the namespace commands to figure out what the tail is. The reason is that ':' is an allowed character in procedure names, and '::', ':::' and '::::' are all equivalent in meaning for qualified names in tcl. The resultant code is also easier to read and maintain.