From: Nick S. <ni...@te...> - 2003-04-09 20:21:56
|
hi all, i'm fiddling around with SPOPS and ran into some problems: as seen in the example code, there is a class My::Commom which provides the method global_datasource_handle(). this method opens a db connection an saves the handle as class variable. other classes created by SPOPS inherit this method, so SPOPS always has access to the db handle via the global_datasource_handle() method. the problem is that everytime you create a new object from one of the SPOPS classes, a new db handle is created, because the connect part in the global_datasource_handle() method is executed. is there a way to save this execution and have *one* db handle for all objects? i don't know a way to pass a dbh reference to the newly created objects, i'd have to override the SPOPS class creation mechanism. has anyone code for this yet? there is something similar in OpenInteract called the "Stash" class, based on the Skeleton class. is this the right place to start? cheers, nick __________________________________________ nick sutterer cb&h productions ni...@te... the computer helps us solving problems which we wouldn't have without it. |
From: Nick S. <ni...@te...> - 2003-04-18 20:45:36
|
hi! how is it possible to create more than one accessor to a "links_to" property in a SPOPS object? SPOPS automatically creates one method which is named according to the object alias: 'object_alias' => { class => My::Object, alias => ['blabla'],... }, 'another_object' => { .... links_to => { 'My::Object' => 'some_linking_table' } } here, an object of type 'another_object' would have one method named 'object_alias' to get the contained objects. although i set an alias in 'object_alias', there is only one accessor in 'another_object', there should be another accessor called 'blabla'. is this correct behaviour? what happens, if a field and a links_to object have the same name? thanks for help and cheers, nick __________________________________________ nick sutterer cb&h productions ni...@te... the computer helps us solving problems which we wouldn't have without it. |
From: Chris W. <ch...@cw...> - 2003-04-21 22:09:44
|
Nick Sutterer wrote: > how is it possible to create more than one accessor to a "links_to" > property in a SPOPS object? SPOPS automatically creates one method which > is named according to the object alias: > > 'object_alias' => { class => My::Object, > alias => ['blabla'],... }, > 'another_object' => { .... > links_to => { 'My::Object' => 'some_linking_table' } > } > > here, an object of type 'another_object' would have one method named > 'object_alias' to get the contained objects. although i set an alias in > 'object_alias', there is only one accessor in 'another_object', there > should be another accessor called 'blabla'. is this correct behaviour? Interesting, this has never come up before. I'm going to take the lazy way out and say that instead of making the code generation more convoluted -- that is, work for me -- you should probably create a couple of aliases in your code class -- work for you, but very easy: sub blabla { my ( $self, @params ) = @_; return $self->object_alias( @params ); } sub blabla_add { my ( $self, @params ) = @_; return $self->object_alias_add( @params ); } sub blabla_remove { my ( $self, @params ) = @_; return $self->object_alias_remove( @params ); } > what happens, if a field and a links_to object have the same name? If this happens you should probably rename one of the two :-) Seriously, the relationship declaration syntax is so ugly right now that I hesitate to add any complexity to it to handle special cases. Later, Chris -- Chris Winters (ch...@cw...) Building enterprise-capable snack solutions since 1988. |
From: Nick S. <ni...@te...> - 2003-04-29 11:01:49
|
hi chris, just a thought: would it be possible and ok to replace the "SPOPS::Secure" string in the object configuration ISA property with a very own security class like "DNT::Security", which is again a SPOPS::Secure subclass *and* implements the 4 necessary security methods like global_user_current? my idea is to let DNT::Security decide which security system to use: it could provide the 4 sec methods in different ways, or could deactivate the security system at all, according to configuration of the DNT::Security class. what do you think about it? cheers, nick __________________________________________ nick sutterer cb&h productions ni...@te... the computer helps us solving problems which we wouldn't have without it. |
From: Chris W. <ch...@cw...> - 2003-04-29 11:18:01
|
Nick Sutterer wrote: > just a thought: would it be possible and ok to replace the "SPOPS::Secure" > string in the object configuration ISA property with a very own security > class like "DNT::Security", which is again a SPOPS::Secure subclass *and* > implements the 4 necessary security methods like global_user_current? > > my idea is to let DNT::Security decide which security system to use: it > could provide the 4 sec methods in different ways, or could deactivate the > security system at all, according to configuration of the DNT::Security > class. > > what do you think about it? Sounds great! It should be fairly amenable to subclassing since SPOPS::Secure::Hierarchy is a subclass of SPOPS::Secure. SPOPS::Secure itself could use some cleanup in terms of interface and naming (e.g., why is there check_action_security(), check_security() and get_security()? ack!), so if you have any ideas speak up. Later, Chris -- Chris Winters (ch...@cw...) Building enterprise-capable snack solutions since 1988. |
From: Nick S. <ni...@te...> - 2003-04-29 11:44:53
|
hi again! is there a way to get information about the properties of a SPOPS object, like fieldnames, related objects, and so on? i think i read about such a mechanism, but couldn't find it in the manual. cheers, nick __________________________________________ nick sutterer cb&h productions ni...@te... the computer helps us solving problems which we wouldn't have without it. |
From: Chris W. <ch...@cw...> - 2003-04-29 12:20:11
|
Nick Sutterer wrote: > is there a way to get information about the properties of a SPOPS object, > like fieldnames, related objects, and so on? > i think i read about such a mechanism, but couldn't find it in the manual. You always have access to an SPOPS object's configuration using the class method CONFIG: my $conf = $spops_class->CONFIG; print "Fields are: ", join( ', ', $conf->{field_list} ); Some of the properties are accessible directly via class methods: print "Fields are: ", join( ', ', $spops_class->field_list ), "and the ID field is: ", $spops_class->id_field; I'm almost positive we're not tracking related objects directly, but since you have access to the configuration you can parse the 'has_a' and 'links_to' declarations to get the information. This is non-optimal, and suggestions are welcome. Later, Chris |
From: Nick S. <ni...@te...> - 2003-04-21 21:12:01
|
hi all, the SPOPS relation manual reads the following: ${alias}_add( $id | $object | \@id_list | \@object_list ) - Adds links to the related objects in $object however, when i try to _add($object) an object this way (passing the reference) i get an error, because SPOPS doesn't dereference the object reference and doesn't call ->id(). when i do this myself _add( $object->id() ), everything works fine. is the manual wrong? cheers, nick __________________________________________ nick sutterer cb&h productions ni...@te... the computer helps us solving problems which we wouldn't have without it. |
From: Chris W. <ch...@cw...> - 2003-04-21 22:02:08
|
Nick Sutterer wrote: > the SPOPS relation manual reads the following: > > ${alias}_add( $id | $object | \@id_list | \@object_list ) - Adds links to > the related objects in $object > > however, when i try to _add($object) an object this way (passing the > reference) i get an error, because SPOPS doesn't dereference the object > reference and doesn't call ->id(). > when i do this myself _add( $object->id() ), everything works fine. > > is the manual wrong? Yes, but the code will catch up with the manual in the next release. Thanks for the report. Chris -- Chris Winters (ch...@cw...) Building enterprise-capable snack solutions since 1988. |
From: Chris W. <ch...@cw...> - 2003-04-09 21:27:02
|
Nick Sutterer wrote: > ... > the problem is that everytime you create a new object from one of the > SPOPS classes, a new db handle is created, because the connect part in > the global_datasource_handle() method is executed. is there a way to save > this execution and have *one* db handle for all objects? i don't know a > way to pass a dbh reference to the newly created objects, i'd have to > override the SPOPS class creation mechanism. has anyone code for this yet? That isn't supposed to happen. The whole idea behind placing global_datasource_handle() in a parent class is that they all use the same database handle. I'll try to take a look at it this evening. Thanks, Chris |
From: Chris W. <ch...@cw...> - 2003-04-10 12:27:04
|
Nick Sutterer wrote: > ... > the problem is that everytime you create a new object from one of the > SPOPS classes, a new db handle is created, because the connect part in > the global_datasource_handle() method is executed. is there a way to save > this execution and have *one* db handle for all objects? i don't know a > way to pass a dbh reference to the newly created objects, i'd have to > override the SPOPS class creation mechanism. has anyone code for this yet? After a simple test I'm not seeing this. I just added a 'warn' to the method in My::Common like this: sub global_datasource_handle { return $DB if ( $DB ); warn "Creating new connection..."; $DB = DBI->connect( ... ); } So every time it creates a new connection (or *thinks* it should create a new connection) it lets me know. Running the various scripts in eg/ produces the expected results: -------------------- $ perl stock_user_group.pl Creating new connection... at My/Common.pm line 64. Created user with ID: 1 Created user with ID: 2 Created user with ID: 3 Created user with ID: 4 Created user with ID: 5 Created user with ID: 6 Created user with ID: 7 Created group with ID: 1 Created group with ID: 2 Created group with ID: 3 -------------------- -------------------- $ perl fetch_all.pl Creating new connection... at My/Common.pm line 64. Added 'set_creator' to My::Doodad User 1: superuser User 2: UserA User 3: UserB ... Group 1: admin Group 2: public Group 3: managers Group [1] User [6] Group [1] User [7] Group [2] User [1] Group [2] User [2] Group [2] User [3] ... Security 1 [My::User] [1] [w] [world] [4] Security 2 [My::User] [1] [g] [3] [8] Security 3 [My::User] [2] [w] [world] [4] Security 4 [My::User] [2] [g] [3] [8] Security 5 [My::User] [3] [w] [world] [4] Security 6 [My::User] [3] [g] [3] [8] ... -------------------- -------------------- $ perl stock_doodads.pl Creating new connection... at My/Common.pm line 64. Added 'set_creator' to My::Doodad Created doodad with ID: 1 Created doodad with ID: 2 Created doodad with ID: 3 Created doodad with ID: 4 -------------------- So every time it just creates a single connection and then reuses it for everything. Some things to check (sorry if they're obvious, no offense): * Is your common class in the object's 'isa'? * Is the common class before SPOPS::DBI in the object's 'isa'? * Is there a scoping issue with the variable you're saving the handle into (e.g., accidentally declaring 'my ( $DB )' in the 'global_datasource_handle()' method? Good luck, Chris -- Chris Winters (ch...@cw...) Building enterprise-capable snack solutions since 1988. |
From: Nick S. <ni...@te...> - 2003-04-10 13:27:49
|
> So every time it creates a new connection (or *thinks* it should > create a new connection) it lets me know. Running the various > scripts in eg/ produces the expected results: > hi chris, sure you're right!! i did not see that the My::Common class is kinda "static". i hope this technique will work in my code! thanks a lot =:-) cheers, nick __________________________________________ nick sutterer cb&h productions ni...@te... the computer helps us solving problems which we wouldn't have without it. |