Mozilla::Prefs::Simple - Manipulate Mozilla preferences
use Mozilla::Prefs::Simple; my $p = new Mozilla::Prefs::Simple('prefs.js'); $p->set_pref("browser.blink_allowed", "true"); $p->set_pref("general.useragent.locale", "\"en-US\""); if ($p->get_pref("mailnews.reply_header_type") == 2) { ... } $p->save_file('prefs.js');
This is a no-frills module for reading and writing Mozilla preference files.
Create a new preferences object.
my $p = new Mozilla::Prefs::Simple(); my $p = new Mozilla::Prefs::Simple('prefs.js');
$p->clear;
Erase the existing preferences. Called by "new" method.
$p->load_file('prefs.js');
Loads a preferences file.
If preferences are already set, they will be overwritten or merged with the ones in the file.
$p->set_pref("some.bool", "true"); $p->set_pref("some.int", 12345); $p->set_pref("some.string", "\"value\"");
Sets the values of preferences.
Note that the values are JavaScript terms, so if you are setting a string value, then it should be enclosed in quotes. To make this less annoying, you can use the "set_pref_q" method, which adds quotes for you:
$p->set_pref_q("some.string", "value");
my $val = $p->get_pref("some.pref");
Returns the value of a preference.
if ($p->has_pref("some.pref")) { ... }
Checks for the existence of a preference.
$p->print_pref("some.pref", $fh);
Prints the JavaScript preference line to $fh.
$fh
$p->print_prefs($fh);
Prints out all of the preferences to the filehandle. If no filehandle is given, STDOUT is assumed.
STDOUT
$p->save_file('prefs.js');
Saves the preferences to the given filename.
If the file exists, a backup copy is made of the original.
This module does very little to validate data. When using it, make sure that you backup your preferences beforehand.
The current version does not parse JavaScript comments. In theory, a user-preference that occurs inside a comment will not be ignored. In practice, applications like Firefox and Thunderbird do not save preferences in comments, so this should not be a problem.
Robert Rothenberg, <rrwo at cpan.org>
<rrwo at cpan.org>
Please report bugs to http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mozilla-Prefs-Simple.
Copyright 2008 Robert Rothenberg, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Mozilla::Prefs::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mozilla::Prefs::Simple
CPAN shell
perl -MCPAN -e shell install Mozilla::Prefs::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.