Author: dylan
Date: 2005-01-23 16:39:28 -0500 (Sun, 23 Jan 2005)
New Revision: 605

Modified:
   trunk/main/core/lib/Haver/Config.pm
   trunk/main/core/lib/Haver/Logger/Functions.pm
Log:
new logger functions and Haver::Config has documentation.


Modified: trunk/main/core/lib/Haver/Config.pm
===================================================================
--- trunk/main/core/lib/Haver/Config.pm 2005-01-23 06:35:30 UTC (rev 604)
+++ trunk/main/core/lib/Haver/Config.pm 2005-01-23 21:39:28 UTC (rev 605)
@@ -1,27 +1,11 @@
-# vim: set ft=perl ts=4 sw=4 sta si ai tw=100 expandtab:
-# Haver::Config - Config manager.
-# 
-# Copyright (C) 2004 Dylan William Hardison.
-# 
-# This module is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This module is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this module; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# vim: set ts=4 sw=4 expandtab si ai sta tw=100:
+# This module is copyrighted, see end of file for details.
 package Haver::Config;
 use strict;
 use warnings;
+use base 'Haver::Base';
 
-use Haver::Preprocessor;
-use base 'Haver::Base';
+use Haver::Base;
 use Scalar::Util 'reftype';
 use Carp;
 use YAML ();
@@ -38,7 +22,6 @@
     }
 }
 
-
 sub load {
     my ($me, $file) = @_;
     my $config;
@@ -89,7 +72,8 @@
 
 # Author: bdonlan
 sub merge_hash {
-       # ASSERT: reftype($_[0]) eq 'HASH' and reftype($_[1]) eq 'HASH';
+       croak 'merge_hash($a,$b): $a and $b must be hashes!' 
+        unless reftype($_[0]) eq 'HASH' and reftype($_[1]) eq 'HASH';
        my ($left, $right) = @_;
        my %merged = %$left;
        for (keys %$right) {
@@ -104,7 +88,8 @@
 
 # Author: bdonlan
 sub merge_array {
-       # ASSERT: reftype($_[0]) eq 'ARRAY' and reftype($_[1]) eq 'ARRAY';
+    croak 'merge_array($a, $b): $a and $b must be arrays!'
+        unless reftype($_[0]) eq 'ARRAY' and reftype($_[1]) eq 'ARRAY';
        my ($left, $right) = @_;
        return [EMAIL PROTECTED], @$right];
 }
@@ -112,3 +97,102 @@
 
 
 1;
+
+
+1;
+__END__
+
+=head1 NAME
+
+Haver::Config - description
+
+=head1 SYNOPSIS
+
+    use Haver::Config;
+    my $ch = new Haver::Config(
+        -file => "$ENV{HOME}/.myconfigfile",
+        -default => {
+            name => $ENV{USER},
+            stuff => [1,2,3],
+        },
+    );
+    my $config = $ch->config;
+    $config->{name} eq $ENV{USER}; # true.
+    $ch->save;
+  
+=head1 DESCRIPTION
+
+This is a simple class to allow the loading and saving of config
+files written in L<YAML> format.
+
+In the future it might provide a way of finding config files in a 
cross-platform way
+or even storing the config data in the Registry on Win32 platforms.
+
+=head1 INHERITENCE
+
+Haver::Config extends L<Haver::Base>.
+
+=head1 CONSTRUCTOR
+
+The constructor new() takes the following parameters:
+
+=head2 -file
+
+The name of the config file to use.
+
+=head2 -default
+
+A hash to merge the config file with. This specifies the default values
+for the application.
+
+=head1 METHODS
+
+This class implements the following methods:
+
+=head2 load($file)
+
+This loads the file $file. Note that:
+
+  my $ch = new Haver::Config;
+  $ch->load('foo')
+
+is equivelent to:
+
+  my $ch = new Haver::Config(-file => 'foo');
+
+=head2 save($file)
+
+Save the config hash to $file. If $file is undefined,
+it defaults to the file that the config was loaded from most recently.
+
+=head1 BUGS
+
+None known. Bug reports are welcome. Please use our bug tracker at
+L<http://gna.org/bugs/?func=additem&group=haver>.
+
+=head1 AUTHOR
+
+Dylan William Hardison, E<lt>[EMAIL PROTECTED]<gt>
+
+=head1 SEE ALSO
+
+L<http://www.haverdev.org/>.
+
+=head1 COPYRIGHT and LICENSE
+
+Copyright (C) 2005 by Dylan William Hardison. All Rights Reserved.
+
+This module is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This module is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this module; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+

Modified: trunk/main/core/lib/Haver/Logger/Functions.pm
===================================================================
--- trunk/main/core/lib/Haver/Logger/Functions.pm       2005-01-23 06:35:30 UTC 
(rev 604)
+++ trunk/main/core/lib/Haver/Logger/Functions.pm       2005-01-23 21:39:28 UTC 
(rev 605)
@@ -3,14 +3,15 @@
 package Haver::Logger::Functions;
 use strict;
 use warnings;
-
+use Haver::Logger;
 use base 'Exporter';
 
 our $VERSION = 0.03;
-our @EXPORT_OK = qw( err crit emerg );
+our @EXPORT_OK = qw( logger );
 
 {
     no strict 'refs';
+    my $logger    = instance Haver::Logger;
     my @functions = qw(
         debug  info
         notice warning
@@ -19,16 +20,16 @@
     );
     foreach my $func (@functions) {
         *$func = sub {
-            $Logger->log(level => $func, message => $_[0]);
+            $logger->log(level => $func, message => $_[0]);
         };
         push @EXPORT_OK, $func;
     }
+    sub logger {
+        $logger->log(level => shift, message => shift);
+    }
 }
 
-*crit = \&critical;
-*err  = \&error;
 
-
 1;
 __END__
 


Reply via email to