Line 60: |
Line 60: |
| | | |
| Should the $new_config_file already exist or for some reason you can't write to it, esmith::DB->error will return the reason and create() will return false. | | Should the $new_config_file already exist or for some reason you can't write to it, esmith::DB->error will return the reason and create() will return false. |
| + | |
| + | example for creating and using a custom database in one line: |
| + | my $customDB = esmith::ConfigDB->open('YOUR_DATABASE_NAME') || esmith::ConfigDB->create('YOUR_DATABASE_NAME'); |
| + | |
| ===== open ===== | | ===== open ===== |
| | | |
Line 98: |
Line 102: |
| | | |
| see also [http://wiki.contribs.org/Esmith::DB::db#creating_a_new_record that page] | | see also [http://wiki.contribs.org/Esmith::DB::db#creating_a_new_record that page] |
| + | |
| + | |
| + | for example (if it doesn't exist we create it) |
| + | my $rec = $DB->get('roundcube') || $DB->new_record('roundcube', {type => 'service'}); |
| | | |
| ===== get ===== | | ===== get ===== |
Line 106: |
Line 114: |
| | | |
| If there's no record for the $key it will return false. | | If there's no record for the $key it will return false. |
| + | |
| + | for example (if it doesn't exist we create it) |
| + | my $rec = $DB->get('roundcube') || $DB->new_record('roundcube', {type => 'service'}); |
| + | |
| ===== get_all ===== | | ===== get_all ===== |
| | | |
Line 111: |
Line 123: |
| | | |
| Gets all the records out of the given $db as a list of esmith::DB::Record objects. | | Gets all the records out of the given $db as a list of esmith::DB::Record objects. |
| + | |
| + | here an example |
| + | |
| + | { |
| + | use esmith::HostsDB; |
| + | $DB = esmith::HostsDB->open; |
| + | |
| + | # Purge quoting chars in comments to fix bug 8723 & bug 8806 |
| + | foreach my $host ($DB->get_all) |
| + | { |
| + | my $comment = $host->prop('Comment'); |
| + | next unless $comment; |
| + | $comment =~ s/['"]//g; |
| + | $host->merge_props(Comment => $comment); |
| + | } |
| + | } |
| | | |
| ==== Concrete methods ==== | | ==== Concrete methods ==== |