SPOPS::Manual::Object

SPOPS::Manual::Object is a Perl module that shows how you interact with SPOPS objects.
Download

SPOPS::Manual::Object Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Chris Winters
  • Publisher web site:
  • http://search.cpan.org/~cwinters/SPOPS-0.87/SPOPS/SQLInterface.pm

SPOPS::Manual::Object Tags


SPOPS::Manual::Object Description

SPOPS::Manual::Object is a Perl module that shows how you interact with SPOPS objects. SPOPS::Manual::Object is a Perl module that shows how you interact with SPOPS objects.This section of the SPOPS manual should be of interest to users and developers, since it describes how SPOPS objects are used. Note that all examples here assume the SPOPS class has already been created -- for more on this see SPOPS::Manual::Configuration and SPOPS::Manual::CodeGeneration for more information about that process.A Simple ExampleHow better to start off than a simple example. Here we get values from CGI.pm, set the values into a new SPOPS object and save it: 1: my $q = new CGI; 2: my $obj = MyUserClass->new(); 3: foreach my $field ( qw( f_name l_name birthdate ) ) { 4: $obj->{ $field } = $q->param( $field ); 5: } 6: my $object_id = eval { $obj->save }; 7: if ( $@ ) { 8: ... report error information ... 9: } 10: else { 11: warn " Object saved with ID: $obj->{object_id}n"; 12: }You can then display this object's information from a later request: 1: my $q = new CGI; 2: my $object_id = $q->param( 'object_id' ); 3: my $obj = MyUserClass->fetch( $object_id ); 4: print "First Name: $obj->{f_name}n", 5: "Last Name: $obj->{l_name}n", 6: "Birthday: $obj->{birthdate}n";To display other information from the same object, like related objects: 1: my $user_group = $obj->group; 2: print "Group Name: $user_group->{name}n";And you can fetch batches of objects at once based on arbitrary criteria: 1: my $q = new CGI; 2: my $last_name = $q->param( 'last_name' ); 3: my $user_list = MyUserClass->fetch_group({ where => 'l_name LIKE ?', 4: value => , 5: order => 'birthdate' }); 6: print "Users with last name having: $last_namen"; 7: foreach my $user ( @{ $user_list } ) { 8: print " $user->{f_name} $user->{l_name} -- $user->{birthdate}n"; 9: } Requirements: · Perl


SPOPS::Manual::Object Related Software