Author: dylan
Date: 2005-05-09 14:12:22 -0400 (Mon, 09 May 2005)
New Revision: 678

Modified:
   trunk/
   trunk/main/core/lib/Haver/Base.pm
   trunk/main/core/lib/Haver/Base/Session.pm
Log:
 [EMAIL PROTECTED]:  dylan | 2005-05-09 14:11:53 -0400
 Haver::Base::Session now re-numbers SESSION, HEAP, KERNEL, ARG0, etc.
 It does this because it is spiffy module, so $_[OBJECT] is shifted off the 
front.
 I like using spiffy filtering, and I don't want to have to give each
 method-that-is-a-state a prototype to prevent it from having $self shifted off.
 So, we remove one from every POE::Session constant.
 Also we don't export OBJECT. use $self instead of $_[OBJECT] in 
POE::Base::Session
 subclasses.
 
 However, this means POE::Base::Session classes assume you're using 
POE::Session (and not,
 say, POE::NFa). Also, if you don't use spiffy filtering, the numbers will be 
wrong.
 You can fix this by doing "use POE::Session".
 However, do not "use POE::Session" if you don't want that.
 
 Still the benefits out-weigh the costs. POE::Base::Session makes it very easy 
to write
 session modules. Also it would be very confusing to have some modules in 
Haver::Server be
 'spiffy filtered' and others not. 
 
 One possibility that I didn't explore was extending the source filtering of 
Spiffy.pm
 in POE::Base::Session to allow structures like this:
 
 
 state foobar {
    ...
 }
 
 translated into:
 
 state 'foobar';
 sub foobar {
    ...
 }
 
 thus avoiding the spiffy magic with normal "sub" definitions. This actually 
could result
 in very concise Session modules. However, source filters much more complicated 
than
 Spiffy.pm are generally bad. What do you think?
 
 
 ###
 
 Haver::Base -- I added DEBUG symbol, exported into all base classes.
 Haver::Base will only check for duplicate field()s when DEBUG is true, as well.
 
 



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:11166
1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk-merge-10131:11178
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
e9404bb1-7af0-0310-a7ff-e22194cd388b:/haver/local:949
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238
   + 1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk:11166
1f59643a-e6e5-0310-bc24-f7d4c744f460:/haver/local/trunk-merge-10131:11178
27e50396-46e3-0310-8b22-ae223a1f35ce:/local:212
e9404bb1-7af0-0310-a7ff-e22194cd388b:/haver/local:951
edfcd8bd-4ce7-0310-a97e-bb1efd40edf3:/local:238

Modified: trunk/main/core/lib/Haver/Base/Session.pm
===================================================================
--- trunk/main/core/lib/Haver/Base/Session.pm   2005-05-09 03:37:48 UTC (rev 
677)
+++ trunk/main/core/lib/Haver/Base/Session.pm   2005-05-09 18:12:22 UTC (rev 
678)
@@ -2,10 +2,10 @@
 # This module is copyrighted, see end of file for details.
 package Haver::Base::Session;
 use Haver::Base '-Base';
-use POE::Session;
 
+our $VERSION = 0.05;
 our @EXPORT_BASE = qw(
-       OBJECT SESSION
+       SESSION
        KERNEL HEAP STATE
        SENDER CALLER_FILE
        CALLER_LINE ARG0
@@ -13,10 +13,43 @@
        ARG4 ARG5 ARG6
        ARG7 ARG8 ARG9
        state states
+       Log
 );
-our $VERSION = 0.04;
 
-sub create {
+BEGIN { require POE::Session };
+use constant {
+       SESSION => POE::Session::SESSION - 1,
+       KERNEL => POE::Session::KERNEL - 1,
+       HEAP => POE::Session::HEAP - 1,
+       STATE => POE::Session::STATE - 1,
+       SENDER => POE::Session::SENDER - 1,
+       CALLER_FILE => POE::Session::CALLER_FILE - 1,
+       CALLER_LINE => POE::Session::CALLER_LINE - 1,
+       ARG0 => POE::Session::ARG0 - 1,
+       ARG1 => POE::Session::ARG1 - 1,
+       ARG2 => POE::Session::ARG2 - 1,
+       ARG3 => POE::Session::ARG3 - 1,
+       ARG4 => POE::Session::ARG4 - 1,
+       ARG5 => POE::Session::ARG5 - 1,
+       ARG6 => POE::Session::ARG6 - 1,
+       ARG7 => POE::Session::ARG7 - 1,
+       ARG8 => POE::Session::ARG8 - 1,
+       ARG9 => POE::Session::ARG9 - 1,
+};
+
+
+
+sub Log (@) {
+       if (@_ == 1) {
+               $POE::Kernel::poe_kernel->post('Logger', 'debug', @_);
+       } elsif (@_ > 1) {
+               $POE::Kernel::poe_kernel->post('Logger', @_);
+       } else {
+               croak 'Log() must be called with >= 1 arguments';
+       }
+}
+
+sub create () {
        my $this = shift;
        my $what = ref $this ? 'object' : 'package';
 
@@ -39,7 +72,7 @@
 
 
 # TODO: Inherit states.
-sub _states {
+sub _states ($) {
        my ($package) = @_;
        no strict 'refs';
        return [EMAIL PROTECTED]('::', $package, '_STATES')};

Modified: trunk/main/core/lib/Haver/Base.pm
===================================================================
--- trunk/main/core/lib/Haver/Base.pm   2005-05-09 03:37:48 UTC (rev 677)
+++ trunk/main/core/lib/Haver/Base.pm   2005-05-09 18:12:22 UTC (rev 678)
@@ -3,26 +3,31 @@
 package Haver::Base;
 use Spiffy qw( -Base );
 use Carp;
+use constant DEBUG => 1;
 
-our @EXPORT_BASE = qw( field croak carp confess );
+our @EXPORT_BASE = qw( DEBUG field croak carp confess );
+
 {
 no warnings;
 sub field(@) {
     use warnings;
     my $package = caller;
-    my ($args, @values) = do {
-        no warnings;
-        local *boolean_arguments = sub { (qw( -weak -force )) };
-        local *paired_arguments = sub { (qw(  -package -init )) };
-        Haver::Base->parse_arguments(@_);
-    };
-    my ($field, $default) = @values;
-    if (my $sub = $package->can($field) and not $args->{'-force'}) {
-        require B;
-        my $p = B::svref_2object($sub)->START->stashpv;
-        if ($p ne $package) {
-            croak "Warning: redefining field $field in $package (Previously 
defined in $p)\n\t";
-        }
+
+    if (DEBUG) {
+       my ($args, @values) = do {
+               no warnings;
+               local *boolean_arguments = sub { (qw( -weak -force )) };
+               local *paired_arguments = sub { (qw(  -package -init )) };
+               Haver::Base->parse_arguments(@_);
+       };
+       my ($field, $default) = @values;
+       if (my $sub = $package->can($field) and not $args->{'-force'}) {
+               require B;
+               my $p = B::svref_2object($sub)->START->stashpv;
+               if ($p ne $package) {
+               croak "Warning: redefining field $field in $package (Previously 
defined in $p)\n\t";
+               }
+       }
     }
     Spiffy::field (-package => $package, @_);}
 }


Reply via email to