DBM-Deep

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    *   delete()

        Deletes one hash key/value pair or array element. Takes one
        argument: the hash key or array index. Returns the data that the
        element used to contain (just like Perl's "delete" function), which
        is "undef" if it did not exist. For arrays, the remaining elements
        located after the deleted element are NOT moved over. The deleted
        element is essentially just undefined, which is exactly how Perl's
        internal arrays work.

          $db->delete("foo"); # for hashes
          $db->delete(1); # for arrays

    *   clear()

        Deletes all hash keys or array elements. Takes no arguments. No
        return value.

          $db->clear(); # hashes or arrays

    *   lock() / unlock() / lock_exclusive() / lock_shared()

        q.v. "LOCKING" for more info.

    *   optimize()

        This will compress the datafile so that it takes up as little space
        as possible. There is a freespace manager so that when space is
        freed up, it is used before extending the size of the datafile. But,
        that freespace just sits in the datafile unless "optimize()" is
        called.

        "optimize" basically copies everything into a new database, so, if
        it is in version 1.0003 format, it will be upgraded.

    *   import()

        Unlike simple assignment, "import()" does not tie the right-hand
        side. Instead, a copy of your data is put into the DB. "import()"
        takes either an arrayref (if your DB is an array) or a hashref (if
        your DB is a hash). "import()" will die if anything else is passed
        in.

    *   export()

        This returns a complete copy of the data structure at the point you
        do the export. This copy is in RAM, not on disk like the DB is.

    *   begin_work() / commit() / rollback()

        These are the transactional functions. "TRANSACTIONS" for more
        information.

    *   supports( $option )

        This returns a boolean indicating whether this instance of DBM::Deep
        supports that feature. $option can be one of:

        *   transactions

        *   unicode

    *   db_version()

        This returns the version of the database format that the current
        database is in. This is specified as the earliest version of
        DBM::Deep that supports it.

        For the File back end, this will be 1.0003 or 2.

        For the DBI back end, it is currently always 1.0020.

  Hashes
    For hashes, DBM::Deep supports all the common methods described above,
    and the following additional methods: "first_key()" and "next_key()".

    *   first_key()

        Returns the "first" key in the hash. As with built-in Perl hashes,
        keys are fetched in an undefined order (which appears random). Takes
        no arguments, returns the key as a scalar value.

          my $key = $db->first_key();

    *   next_key()

        Returns the "next" key in the hash, given the previous one as the
        sole argument. Returns undef if there are no more keys to be
        fetched.

          $key = $db->next_key($key);

    Here are some examples of using hashes:

      my $db = DBM::Deep->new( "foo.db" );

      $db->put("foo", "bar");
      print "foo: " . $db->get("foo") . "\n";

      $db->put("baz", {}); # new child hash ref
      $db->get("baz")->put("buz", "biz");
      print "buz: " . $db->get("baz")->get("buz") . "\n";

      my $key = $db->first_key();
      while ($key) {
          print "$key: " . $db->get($key) . "\n";
          $key = $db->next_key($key);
      }

      if ($db->exists("foo")) { $db->delete("foo"); }

  Arrays
    For arrays, DBM::Deep supports all the common methods described above,
    and the following additional methods: "length()", "push()", "pop()",
    "shift()", "unshift()" and "splice()".

    *   length()

        Returns the number of elements in the array. Takes no arguments.

          my $len = $db->length();



( run in 0.996 second using v1.01-cache-2.11-cpan-39bf76dae61 )