Robert Rothenberg > Mozilla-Prefs-Simple > Mozilla::Prefs::Simple

Download:
Mozilla-Prefs-Simple-0.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Mozilla::Prefs::Simple - Manipulate Mozilla preferences

SYNOPSIS ^

  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');

DESCRIPTION ^

This is a no-frills module for reading and writing Mozilla preference files.

METHODS ^

new

Create a new preferences object.

  my $p = new Mozilla::Prefs::Simple();

  my $p = new Mozilla::Prefs::Simple('prefs.js');
clear
  $p->clear;

Erase the existing preferences. Called by "new" method.

load_file
  $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.

set_pref
set_pref_q
  $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");
get_pref
  my $val = $p->get_pref("some.pref");

Returns the value of a preference.

has_pref
  if ($p->has_pref("some.pref")) {
    ...
  }

Checks for the existence of a preference.

print_pref
  $p->print_pref("some.pref", $fh);

Prints the JavaScript preference line to $fh.

print_prefs
  $p->print_prefs($fh);

Prints out all of the preferences to the filehandle. If no filehandle is given, STDOUT is assumed.

save_file
  $p->save_file('prefs.js');

Saves the preferences to the given filename.

If the file exists, a backup copy is made of the original.

CAVEATS ^

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.

AUTHOR ^

Robert Rothenberg, <rrwo at cpan.org>

BUGS ^

Please report bugs to http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mozilla-Prefs-Simple.

COPYRIGHT & LICENSE ^

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.

syntax highlighting: