Author: dylan
Date: 2004-06-04 02:06:14 -0400 (Fri, 04 Jun 2004)
New Revision: 221
Added:
trunk/haver-core/lib/Haver/Util/
trunk/haver-core/lib/Haver/Util/Logger.pm
trunk/haver-core/lib/Haver/Util/Misc.pm
trunk/haver-core/lib/Haver/Util/Reload.pm
Removed:
trunk/haver-core/lib/Haver/Logger.pm
trunk/haver-core/lib/Haver/Misc.pm
trunk/haver-core/lib/Haver/Reload.pm
Log:
Doing some renaming...
Deleted: trunk/haver-core/lib/Haver/Logger.pm
===================================================================
--- trunk/haver-core/lib/Haver/Logger.pm 2004-06-04 02:57:20 UTC (rev
220)
+++ trunk/haver-core/lib/Haver/Logger.pm 2004-06-04 06:06:14 UTC (rev
221)
@@ -1,184 +0,0 @@
-# Haver::Logger - Logger
-#
-# 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
-package Haver::Logger;
-use strict;
-use warnings;
-
-use POE qw( Wheel::ReadWrite Driver::SysRW Filter::Line );
-use Fatal qw( :void open close );
-
-use Haver::Preprocessor;
-
-our $VERSION = "0.01";
-my $Package = __PACKAGE__;
-
-sub create {
- my $class = shift;
- ASSERT: (@_ == 1) or ((@_ % 2) == 0);
- my $opts = @_ == 1 ? $_[0] : { @_ };
-
- create POE::Session (
- package_states => [
- $Package => {
- _start => 'on_start',
- _stop => 'on_stop',
- _default => 'on_default',
- 'shutdown' => 'on_shutdown',
- 'flush' => 'on_flush',
- },
- ],
- args => [ $opts ],
- heap => {
- alias => 'Logger' || delete $opts->{alias},
- },
- );
-}
-
-sub on_start {
- my ($kernel, $heap, $opts) = @_[KERNEL, HEAP, ARG0];
- my %wheels = ();
- my @handles = ();
- my $levels = $opts->{levels};
- my $driver = $opts->{driver} || sub { new POE::Driver::SysRW };
- my $filter = $opts->{filter} || sub { new
POE::Filter::Line(OutputLiteral => "\n") };
-
-
- foreach my $level (keys %$levels) {
- my $file = $opts->{levels}{$level};
- my $fh;
- unless (ref $file) {
- open $fh, ">$file";
- } else {
- $fh = $file;
- }
-
- $wheels{$level} = new POE::Wheel::ReadWrite (
- InputHandle => -1,
- OutputHandle => $fh,
- Driver => $driver->(),
- Filter => $filter->(),
- FlushedEvent => 'flush',
- );
- }
-
- $heap->{wheels} = \%wheels;
-
- $kernel->alias_set($heap->{alias});
- print "Logger starts.\n";
-}
-
-sub on_stop {
- print "Logger stops.\n";
-}
-
-sub on_default {
- my ($kernel, $heap, $level, $args) = @_[KERNEL, HEAP, ARG0, ARG1];
- my $msg = $args->[0];
-
- if ($level =~ /^_/) {
- return 0;
- }
-
- if (exists $heap->{wheels}{$level}) {
- $heap->{wheels}{$level}->put($msg);
- } elsif (exists $heap->{wheels}{default}) {
- $heap->{wheels}{default}->put($msg);
- } else {
- print "[$level] $msg\n";
- }
-
-}
-
-sub on_shutdown {
- my ($kernel, $heap) = @_[KERNEL, HEAP];
-
- $kernel->alias_remove($heap->{alias});
- $heap->{shutdown} = 1;
-}
-
-sub on_flush {
- my ($kernel, $heap) = @_[KERNEL, HEAP];
-
- if ($heap->{shutdown}) {
- $heap->{wheels} = {};
- }
-}
-
-1;
-
-__END__
-
-=head1 NAME
-
-Haver::Logger - POE-based logging service.
-
-=head1 SYNOPSIS
-
- use Haver::Logger;
- create Haver::Logger (
- levels => {
- alert => 'alert.log',
- error => \*STDERR,
- foo => new IO::File ('bunnies.log'),
- },
- filter => sub { new POE::Filter::Line }, # optional, default
- driver => sub { new POE::Driver::SysRW }, # optional, default
- alias => 'Logger' # optional, default
- );
-
- # in some POE-state,
- $kernel->post('Logger', 'alert', 'bunnies');
- $kernel->post('Logger', 'error', 'I have been stolen by aliens');
- $kernel->post('Logger', 'foo', 'bar baz <g>');
-
- # When you're done:
- $kernel->post('Logger', 'shutdown');
-
-
-=head1 DESCRIPTION
-
-FIXME: Document this.
-
-=head1 SEE ALSO
-
-L<https://gna.org/projects/haver/>
-
-
-=head1 AUTHOR
-
-Dylan William Hardison, E<lt>[EMAIL PROTECTED]<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright (C) 2004 by Dylan William Hardison
-
-This library 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 library 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
-
-=cut
Deleted: trunk/haver-core/lib/Haver/Misc.pm
===================================================================
--- trunk/haver-core/lib/Haver/Misc.pm 2004-06-04 02:57:20 UTC (rev 220)
+++ trunk/haver-core/lib/Haver/Misc.pm 2004-06-04 06:06:14 UTC (rev 221)
@@ -1,45 +0,0 @@
-# Haver::Misc - Various routines
-#
-# 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
-package Haver::Misc;
-use strict;
-#use warnings;
-use Haver::Preprocessor;
-use POSIX qw( strftime );
-use Carp;
-use Exporter;
-use base 'Exporter';
-
-
-our @EXPORT_OK = qw( format_datetime randint rand );
-our $VERSION = '0.01';
-our $RELOAD = 1;
-
-
-sub format_datetime {
- # dylan: Because bd_ thought it should work this way...
- ASSERT: @_ <= 1;
- my $now = @_ ? shift : time;
-
- strftime('%Y-%m-%d %H:%M:%S %z', localtime($now));
-}
-
-sub parse_datetime {
- # WRITEME
-}
-
-1;
Deleted: trunk/haver-core/lib/Haver/Reload.pm
===================================================================
--- trunk/haver-core/lib/Haver/Reload.pm 2004-06-04 02:57:20 UTC (rev
220)
+++ trunk/haver-core/lib/Haver/Reload.pm 2004-06-04 06:06:14 UTC (rev
221)
@@ -1,184 +0,0 @@
-# Haver::Reload - Reload modules.
-#
-# 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
-package Haver::Reload;
-use strict;
-use warnings;
-use File::stat;
-
-our $VERSION = '0.01';
-our %Stat;
-our $Pattern = qr/^Haver::/;
-our $RELOAD = 1;
-
-sub init {
- foreach my $key (keys %INC) {
- my $mod = $key;
- $mod =~ s!/!::!g;
- $mod =~ s/\.pm$//;
- unless ($mod =~ $Pattern) {
- next;
- }
- $Stat{$key} = stat($INC{$key})->mtime;
- }
-}
-
-sub pattern {
- my ($this, $pat) = @_;
- if (ref($pat) eq 'Regexp') {
- $Pattern = $pat;
- }
-}
-
-sub load {
- my ($this, $mod) = @_;
- my $file = $mod;
- $file =~ s!::!/!g;
- $file .= '.pm';
- eval {
- require $file;
- };
- if ($@) {
- warn "Error loading ${mod}: $@";
- return 0;
- } else {
- $Stat{$file} = stat($INC{$file})->mtime;
- return 1;
- }
-}
-
-sub reload {
- my %mods;
- my $mtime;
- my @did;
-
- while (my ($key, $file) = each %INC) {
- my $file = $INC{$key};
- my $mod = $key;
- $mod =~ s!/!::!g;
- $mod =~ s/\.pm$//;
-
- unless ($mod =~ $Pattern) {
- next;
- }
-
- $mtime = stat($file)->mtime;
- no strict 'refs';
- unless (defined ${"${mod}::RELOAD"}) {
- print "\$${mod}::RELOAD is not set\n";
- next;
- }
- use strict 'refs';
-
- if ($mtime > $Stat{$key}) {
- local $^W = 0;
- push(@did, $mod);
- delete $INC{$key};
- eval {
- require $key;
- };
- if ($@) {
- warn "Error reloading ${mod}: $@";
- $INC{$key} = $file;
- } else {
- if (my $code = $mod->can('RELOAD')) {
- eval { $code->($mod) };
- }
- }
- }
- } continue {
- if (defined $mtime) {
- $Stat{$key} = $mtime;
- }
- $mtime = undef;
- }
-
- return @did;
-}
-
-1;
-__END__
-
-=head1 NAME
-
-Haver::Reload - Reload modules if needed
-
-=head1 SYNOPSIS
-
- use Haver::Reload;
- Haver::Reload->init;
-
- # Now, reload things:
- my @did = Haver::Reload->reload;
-
- # @did is a list of modules we reloaded.
-
- # change the default module matching pattern:
- Haver::Reload->pattern(qr/^MyMod::/);
-
- # Try to load a module at run-time:
- if (Haver::Reload->load('Haver::Server::Monkey')) {
- print "OK!\n";
- } else {
- print "Can't load Haver::Server::Monkey!\n";
- }
- # Note, the above is probably always going to be used as a way
- # to force-reload something.
-
-
-
-=head1 DESCRIPTION
-
-This module reloads modules, if the module is reloadable and has changed
-since init() was last called. The module must also match
$Haver::Reload::Pattern,
-which is a regexp thingy, made with qr//.
-A module is considered reloadable if it contains a package global scalar
-$RELOAD and if that said global is true.
-
-$Haver::Reload::Pattern defaults to qr/^Haver::/.
-
-=head2 EXPORTS
-
-Nothing at all.
-
-=head1 SEE ALSO
-
-L<https://savannah.nongnu.org/projects/haver/>
-
-=head1 AUTHOR
-
-Dylan William Hardison, E<lt>[EMAIL PROTECTED]<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright (C) 2004 by Dylan William Hardison
-
-This library 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 library 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
-
-=cut
Copied: trunk/haver-core/lib/Haver/Util/Logger.pm (from rev 217,
trunk/haver-core/lib/Haver/Logger.pm)
===================================================================
--- trunk/haver-core/lib/Haver/Logger.pm 2004-05-31 23:15:00 UTC (rev
217)
+++ trunk/haver-core/lib/Haver/Util/Logger.pm 2004-06-04 06:06:14 UTC (rev
221)
@@ -0,0 +1,184 @@
+# Haver::Logger - Logger
+#
+# 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
+package Haver::Util::Logger;
+use strict;
+use warnings;
+
+use POE qw( Wheel::ReadWrite Driver::SysRW Filter::Line );
+use Fatal qw( :void open close );
+
+use Haver::Preprocessor;
+
+our $VERSION = "0.01";
+my $Package = __PACKAGE__;
+
+sub create {
+ my $class = shift;
+ ASSERT: (@_ == 1) or ((@_ % 2) == 0);
+ my $opts = @_ == 1 ? $_[0] : { @_ };
+
+ create POE::Session (
+ package_states => [
+ $Package => {
+ _start => 'on_start',
+ _stop => 'on_stop',
+ _default => 'on_default',
+ 'shutdown' => 'on_shutdown',
+ 'flush' => 'on_flush',
+ },
+ ],
+ args => [ $opts ],
+ heap => {
+ alias => 'Logger' || delete $opts->{alias},
+ },
+ );
+}
+
+sub on_start {
+ my ($kernel, $heap, $opts) = @_[KERNEL, HEAP, ARG0];
+ my %wheels = ();
+ my @handles = ();
+ my $levels = $opts->{levels};
+ my $driver = $opts->{driver} || sub { new POE::Driver::SysRW };
+ my $filter = $opts->{filter} || sub { new
POE::Filter::Line(OutputLiteral => "\n") };
+
+
+ foreach my $level (keys %$levels) {
+ my $file = $opts->{levels}{$level};
+ my $fh;
+ unless (ref $file) {
+ open $fh, ">$file";
+ } else {
+ $fh = $file;
+ }
+
+ $wheels{$level} = new POE::Wheel::ReadWrite (
+ InputHandle => -1,
+ OutputHandle => $fh,
+ Driver => $driver->(),
+ Filter => $filter->(),
+ FlushedEvent => 'flush',
+ );
+ }
+
+ $heap->{wheels} = \%wheels;
+
+ $kernel->alias_set($heap->{alias});
+ print "Logger starts.\n";
+}
+
+sub on_stop {
+ print "Logger stops.\n";
+}
+
+sub on_default {
+ my ($kernel, $heap, $level, $args) = @_[KERNEL, HEAP, ARG0, ARG1];
+ my $msg = $args->[0];
+
+ if ($level =~ /^_/) {
+ return 0;
+ }
+
+ if (exists $heap->{wheels}{$level}) {
+ $heap->{wheels}{$level}->put($msg);
+ } elsif (exists $heap->{wheels}{default}) {
+ $heap->{wheels}{default}->put($msg);
+ } else {
+ print "[$level] $msg\n";
+ }
+
+}
+
+sub on_shutdown {
+ my ($kernel, $heap) = @_[KERNEL, HEAP];
+
+ $kernel->alias_remove($heap->{alias});
+ $heap->{shutdown} = 1;
+}
+
+sub on_flush {
+ my ($kernel, $heap) = @_[KERNEL, HEAP];
+
+ if ($heap->{shutdown}) {
+ $heap->{wheels} = {};
+ }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Haver::Logger - POE-based logging service.
+
+=head1 SYNOPSIS
+
+ use Haver::Logger;
+ create Haver::Logger (
+ levels => {
+ alert => 'alert.log',
+ error => \*STDERR,
+ foo => new IO::File ('bunnies.log'),
+ },
+ filter => sub { new POE::Filter::Line }, # optional, default
+ driver => sub { new POE::Driver::SysRW }, # optional, default
+ alias => 'Logger' # optional, default
+ );
+
+ # in some POE-state,
+ $kernel->post('Logger', 'alert', 'bunnies');
+ $kernel->post('Logger', 'error', 'I have been stolen by aliens');
+ $kernel->post('Logger', 'foo', 'bar baz <g>');
+
+ # When you're done:
+ $kernel->post('Logger', 'shutdown');
+
+
+=head1 DESCRIPTION
+
+FIXME: Document this.
+
+=head1 SEE ALSO
+
+L<https://gna.org/projects/haver/>
+
+
+=head1 AUTHOR
+
+Dylan William Hardison, E<lt>[EMAIL PROTECTED]<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2004 by Dylan William Hardison
+
+This library 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 library 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
+
+=cut
Copied: trunk/haver-core/lib/Haver/Util/Misc.pm (from rev 217,
trunk/haver-core/lib/Haver/Misc.pm)
Copied: trunk/haver-core/lib/Haver/Util/Reload.pm (from rev 217,
trunk/haver-core/lib/Haver/Reload.pm)