PathMap section

From CunningPlans

(Redirected from PathMap)
Jump to: navigation, search

PathMap is a required section in the baldrick.cfg file. PathMap is used to map URLs to Module sections, and therefore to request handlers and to Modules.

[edit] Syntax


<PathMap>
    path = ModuleName
    path = ModuleName:command
    path = ModuleName:?command
</PathMap>

path
The path matches either the full local path part of the URL, or its last component only. For example, the path http://www.graveyards.com/bin/grave would be matched by either "/bin/grave" or "grave".
ModuleName
Indicates which Module section the request should be sent to. The specified Module will be loaded according to the settings in the Module section.
:command
Optional command to invoke on the specified module. Ordinarily, the command is determined the the CGI parameter "cmd"; this allows it to be overridden. For example, you may wish to have the same ShoppingCart module invoked with paths like "/cart/add" and "/cart/checkout", all of which go to the same module, but with command set to "add" or "checkout".
:?command
Optional command to invoke on the specified module, only if the cmd parameter is absent. Like ':command' (without the question mark) above, but the user can override it.

[edit] Examples

<PathMap>
    # A full path.    
    /bin/blog = BlogModule
    #
    # Last part of the path only.
    blog = BlogModule
    # invoke same module under a different name.
    journal = BlogModule
    # 
    # A shopping cart application.
    /cart/shop = ShoppingCart
    shop = ShoppingCart
    # Send to same module with an implicit command (invoking a handleAdd() function on the handler)
    /cart/additem = ShoppingCart:add
    /cart/removeitem = ShoppingCart:remove
    # Make the implicit command something a user can override
    # (the "?" before the command name means it's just a default; any "cmd=XXXXXX" variable in the user 
    # inputs will take precedence).
    /cart/shop = ShoppingCart:?viewcart
    #
    # Standard stuff that should be on any site.
    login = UserLoginHandler:login
    logout = UserLoginHandler:logout
</PathMap>
<Module BlogModule>
    # A target for the above.  See [[Module section]] for details.
    # (Basically, FredWare::BlogMain is a sublcass of [[Baldrick::Dogsbody]] with various handleXXXXXX() functions)
    handler-class = FredWare::BlogMain  # perl module name ( "::" is OK)
</Module>
<Module ShoppingCart>
    handler-class = BiffCart3000::Shop   
</Module>
Personal tools