use v6; use NativeCall; constant GDBM_BLOCKSIZE = 0; constant GDBM_WRCREAT = 2; constant GDBM_REPLACE = 1; class datum is repr('CStruct') { has Str $.dptr is rw; has int32 $.dsize is rw; } class DBM::GDBM is repr('CPointer') { sub gdbm_open( Str $name, int32 $block_size, int32 $flags, int32 $mode, Pointer[void] $fatal_func ) returns DBM::GDBM is native('libgdbm.so.3') { * } sub gdbm_store( DBM::GDBM $dbf, datum $key, datum $content, int32 $flag, ) returns int32 is native('libgdbm.so.3') { * } method new($gdbm_file_name, $flags, $mode) { return gdbm_open($gdbm_file_name, GDBM_BLOCKSIZE, GDBM_WRCREAT, $mode, Nil); } method store(Str $key is rw, Str $value is rw) { my datum $key_datum = datum.new(dptr => $key, dsize => $key.chars); my datum $content_datum = datum.new(dptr => $value, dsize => $value.chars); return gdbm_store(self, $key_datum, $content_datum, GDBM_REPLACE); } }