use Class::HPLOO ; class User extends HDB::Object { use HDB::Object ; attr( user , pass , name , int age , int create_time ) ; sub User( $user , $pass , $name , $age ) { $this->{user} = $user ; $this->{pass} = $pass ; $this->{name} = $name ; $this->{age} = $age ; $this->{create_time} = time ; } } #### BEGIN { use HDB ; HDB->new( id => 'HPLOO' , type => 'sqlite' , db => './hploo.db' ) ; } use User ; my $new_user = new User('joe' , 12345 , 'Joe Smith' , 30 ) ; $new_user = undef ; ## destroy to commit to the DB. Or just call $new_user->hdb_save. print "-------------------------------------------\n" ; my $user_joe = load User("user eq 'joe'") ; foreach my $attr ( $user_joe->ATTRS ) { print "$attr: $user_joe->{$attr}\n" ; } $user_joe = undef ; ## commit print "-------------------------------------------\n" ; my @users = load User("id < 10") ; foreach my $users_i ( @users ) { ++$users_i->{age} ; } @users = () ; ## commit changes. print "-------------------------------------------\n" ; print User->hdb_dump_table ; print "-------------------------------------------\n" ; #### ------------------------------------------- user: joe pass: 12345 name: Joe Smith age: 30 create_time: 1097971836 ------------------------------------------- ------------------------------------------- TABLE User: user = TEXT pass = TEXT name = TEXT age = INTEGER create_time = INTEGER id = INTEGER PRIMARY KEY ROWS: joe::12345::Joe Smith::44::1097971836::1 joe::12345::Joe Smith::43::1097971838::2 joe::12345::Joe Smith::42::1097971839::3 joe::12345::Joe Smith::41::1097971839::4 joe::12345::Joe Smith::40::1097971840::5 joe::12345::Joe Smith::39::1097971840::6 joe::12345::Joe Smith::38::1097971841::7 joe::12345::Joe Smith::37::1097971842::8 joe::12345::Joe Smith::36::1097971843::9 joe::12345::Joe Smith::30::1097971844::10 joe::12345::Joe Smith::30::1097971845::11 joe::12345::Joe Smith::30::1097971846::12 joe::12345::Joe Smith::30::1097971847::13 joe::12345::Joe Smith::30::1097971848::14 -------------------------------------------