From: Chris W. <ch...@cw...> - 2003-11-18 15:32:42
|
Stathy G. Touloumis wrote: > I was wondering open_interact has built in support for packages > interacting with each other. More specifically I would like to add > 'links' to the 'box' of one application from another application. This > would be similar to how you can do this with boxes in general. Nothing is built-in. Packages communicate with each other like everything else in OI, through common names of registered components. This is normally seen in two ways: - SPOPS object name-to-class mappings 1.x: my $object_class = $R->object_name 2.x: my $object_class = CTX->lookup_object( 'object_name' ) - Action handler name-to-class mappings 1.x: my $action_info_hash = $R->lookup_action( 'action_name', { return => 'info } ); 1.x: my ( $action_class, $method ) = $R->lookup_action( 'action_name' ); 2.x: my $action_obj = CTX->lookup_action( 'action_name' ); my $action_name = CTX->lookup_action_name( 'url' ); my $action_info_hash = CTX->lookup_action_info( 'action_name' ); In 1.x you can also use $R to pass around information as necessary. It's a little hackish (that is, not built-in) but it's fairly easy to do, and all your packages need to agree on is what name to use ('tmp_box_links' in the example below). For instance, in your box handler you could have: sub handler { my ( $class, $params ) = @_; # These are the links used in the box call my $my_links = $params->{links} || []; # These are the links added by other people my $other_links = $R->{tmp_box_links} || []; my @all_links = ( @{ $my_links }, @{ $other_links } ); return $R->template->handler( {}, { links => \@all_links }, { name => 'mypkg::tmpl' } ); } Since OI 2.x represents all actions, including boxes, as objects you can store state in them from anywhere you wish. Much more flexible. Hope this helps, Chris -- Chris Winters (ch...@cw...) Building enterprise-capable snack solutions since 1988. |