[Jifty-commit] r6622 - in jifty/trunk: . lib/Jifty lib/Jifty/Web lib/Jifty/Web/Form

Jifty commits jifty-commit at lists.jifty.org
Tue Mar 17 11:42:34 EDT 2009


Author: sartak
Date: Tue Mar 17 11:42:34 2009
New Revision: 6622

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/CurrentUser.pm
   jifty/trunk/lib/Jifty/Dispatcher.pm
   jifty/trunk/lib/Jifty/Everything.pm
   jifty/trunk/lib/Jifty/Handler.pm
   jifty/trunk/lib/Jifty/Model/Session.pm
   jifty/trunk/lib/Jifty/Object.pm
   jifty/trunk/lib/Jifty/Record.pm
   jifty/trunk/lib/Jifty/Request.pm
   jifty/trunk/lib/Jifty/Web.pm
   jifty/trunk/lib/Jifty/Web/Form/Clickable.pm
   jifty/trunk/lib/Jifty/Web/Form/Element.pm
   jifty/trunk/lib/Jifty/Web/Form/Field.pm
   jifty/trunk/lib/Jifty/Web/Form/Link.pm
   jifty/trunk/lib/Jifty/Web/Menu.pm

Log:
 r81280 at onn:  sartak | 2009-03-17 11:42:22 -0400
 Revert mismerge


Modified: jifty/trunk/lib/Jifty/CurrentUser.pm
==============================================================================
--- jifty/trunk/lib/Jifty/CurrentUser.pm	(original)
+++ jifty/trunk/lib/Jifty/CurrentUser.pm	Tue Mar 17 11:42:34 2009
@@ -77,8 +77,9 @@
     my %args = (@_);
 
     # Duck-typing to check to for a user class
-    if (keys %args and UNIVERSAL::can(Jifty->app_class('Model', 'User'), 'new')  ) {
-        $self->user_object(Jifty->app_class('Model', 'User')->new(current_user => $self));
+    my $user_class = Jifty->app_class({require => 0}, 'Model', 'User');
+    if (keys %args and UNIVERSAL::can($user_class, 'new')  ) {
+        $self->user_object($user_class->new(current_user => $self));
         $self->user_object->load_by_cols(%args);
     }
 
@@ -137,16 +138,14 @@
 sub id {
     my $self = shift;
 
+    # This can be a hotspot, so we don't use method calls, instead
+    # directly accessing the value.
+
     # Make sure we have a user object before trying to ID it
-    if ($self->user_object) {
-        return ($self->user_object->id());
-    } 
-    
-    # No user object, return a null ID
-    else {
-        return '0';
-    }
+    return $self->{user_object}->id if $self->{user_object};
 
+    # No user object, return a null ID
+    return 0;
 }
 
 =head2 current_user

Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm	(original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm	Tue Mar 17 11:42:34 2009
@@ -286,8 +286,9 @@
 >;
 
 our $Dispatcher;
+our $Request;
 
-sub request       { Jifty->web->request }
+sub request       { $Request }
 sub _ret (@);
 sub under ($$@)   { _ret @_ }    # partial match at beginning of path component
 sub before ($$@)  { _ret @_ }    # exact match on the path component
@@ -304,9 +305,9 @@
 sub set ($$@)     { _ret @_ }    # set parameter
 sub del ($@)      { _ret @_ }    # remove parameter
 sub get ($) {
-    my $val = request->template_argument( $_[0] );
+    my $val = $Request->template_argument( $_[0] );
     return $val if defined $val;
-    return request->argument( $_[0] );
+    return $Request->argument( $_[0] );
 }
 
 sub _qualify ($@);
@@ -483,9 +484,10 @@
     # do it once per request. But it's really, really painful when you
     # do it often, as is the case with fragments
     local $SIG{__DIE__} = 'DEFAULT';
+    local $Request = Jifty->web->request;
 
     eval {
-        my $path = Jifty->web->request->path;
+        my $path = $Request->path;
         utf8::downgrade($path); # Mason handle non utf8 path.
         $Dispatcher->_do_dispatch( $path );
     };
@@ -808,21 +810,21 @@
     my ( $self, $key, $value ) = @_;
     no warnings 'uninitialized';
     $self->log->debug("Setting argument $key to $value");
-    request->template_argument($key, $value);
+    $Request->template_argument($key, $value);
 }
 
 sub _do_del {
     my ( $self, $key ) = @_;
     $self->log->debug("Deleting argument $key");
-    request->delete($key);
+    $Request->delete($key);
 }
 
 sub _do_default {
     my ( $self, $key, $value ) = @_;
     no warnings 'uninitialized';
     $self->log->debug("Setting argument default $key to $value");
-    request->template_argument($key, $value)
-        unless defined request->argument($key) or defined request->template_argument($key);
+    $Request->template_argument($key, $value)
+        unless defined $Request->argument($key) or defined $Request->template_argument($key);
 }
 
 =head2 _do_dispatch [PATH]
@@ -919,9 +921,8 @@
     elsif ( ref($cond) eq 'HASH' ) {
         local $@;
         my $rv = eval {
-            for my $key ( sort keys %$cond )
+            for my $key ( sort grep {length} keys %$cond )
             {
-                next if $key eq '';
                 my $meth = "_match_$key";
                 $self->$meth( $cond->{$key} ) or return;
             }
@@ -957,7 +958,7 @@
 sub _match_method {
     my ( $self, $method ) = @_;
     #$self->log->debug("Matching method ".request->request_method." against ".$method);
-    lc( request->request_method ) eq lc($method);
+    $Request->request_method eq uc($method);
 }
 
 =head2 _match_https
@@ -1255,8 +1256,8 @@
 
     # Handle parse errors
     my $err = $@;
-    $self->log->fatal("View error: $err") if $err;
     if ( $err and not eval { $err->isa('HTML::Mason::Exception::Abort') } ) {
+        $self->log->fatal("View error: $err") if $err;
         if ($template eq '/errors/500') {
             $self->log->warn("Can't render internal_error: $err");
             # XXX Built-in static "oh noes" page?
@@ -1279,9 +1280,8 @@
         Jifty->web->_redirect( "/errors/500?J:C=" . $c->id );
     } elsif ($err) {
         Jifty->handler->buffer->pop while Jifty->handler->buffer->depth > $start_depth;
-        die $err;
+        $self->_abort;
     }
-
 }
 
 

Modified: jifty/trunk/lib/Jifty/Everything.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Everything.pm	(original)
+++ jifty/trunk/lib/Jifty/Everything.pm	Tue Mar 17 11:42:34 2009
@@ -40,6 +40,8 @@
 use Jifty::Record ();
 use Jifty::Collection ();
 use Jifty::Action ();
+use Jifty::Action::Autocomplete ();
+use Jifty::Action::Redirect ();
 use Jifty::Action::Record ();
 use Jifty::Action::Record::Create ();
 use Jifty::Action::Record::Update ();

Modified: jifty/trunk/lib/Jifty/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/Handler.pm	Tue Mar 17 11:42:34 2009
@@ -85,6 +85,11 @@
 
     $self->buffer(String::BufferStack->new( out_method => \&Jifty::View::out_method ));
     $self->setup_view_handlers();
+    {
+        my $buffer = $self->buffer;
+        no warnings 'redefine';
+        *Jifty::Web::out = sub {shift;unshift @_,$buffer;goto \&String::BufferStack::append};
+    }
     return $self;
 }
 

Modified: jifty/trunk/lib/Jifty/Model/Session.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Model/Session.pm	(original)
+++ jifty/trunk/lib/Jifty/Model/Session.pm	Tue Mar 17 11:42:34 2009
@@ -58,7 +58,9 @@
 
 =cut
 
-sub current_user { return Jifty->app_class('CurrentUser')->superuser }
+my $SUPERUSER;
+sub current_user { return $SUPERUSER ||= Jifty->app_class('CurrentUser')->superuser }
+sub current_user_can {return 1;}
 
 =head2 new_session_id
 

Modified: jifty/trunk/lib/Jifty/Object.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Object.pm	(original)
+++ jifty/trunk/lib/Jifty/Object.pm	Tue Mar 17 11:42:34 2009
@@ -79,9 +79,8 @@
             my $x = (CORE::caller( $depth++ ))[0];
             my $caller_self = $DB::args[0];
             next unless ref($caller_self);    #skip class methods;
-            next if $caller_self->isa('Jifty::Date'); 
-            next unless $caller_self->can('current_user');
-            next unless my $t = $caller_self->current_user;
+            next unless my $s = $caller_self->can('current_user');
+            next unless my $t = $s->($caller_self);
             next unless defined $t->id;
             $cu = $t;
         }

Modified: jifty/trunk/lib/Jifty/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Record.pm	Tue Mar 17 11:42:34 2009
@@ -250,7 +250,7 @@
 
     # Add plugin table prefix if a plugin model
     my $class = ref($self) ? ref($self) : $self;
-    my $app_plugin_root = Jifty->app_class('Plugin');
+    my $app_plugin_root = Jifty->app_class({require => 0}, 'Plugin');
     if ( $class =~ /^(?:Jifty::Plugin::|$app_plugin_root)/ ) {
 
         # Guess the plugin class name

Modified: jifty/trunk/lib/Jifty/Request.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Request.pm	(original)
+++ jifty/trunk/lib/Jifty/Request.pm	Tue Mar 17 11:42:34 2009
@@ -118,7 +118,7 @@
     my ($cgi) = @_;
 
     # Store away request method
-    $self->request_method( $cgi->request_method );
+    $self->request_method( uc $cgi->request_method );
 
     # Grab content type and posted data, if any
     my $ct   = $ENV{"CONTENT_TYPE"};

Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm	(original)
+++ jifty/trunk/lib/Jifty/Web.pm	Tue Mar 17 11:42:34 2009
@@ -20,7 +20,7 @@
 use vars qw/$SERIAL @JS_INCLUDES/;
 
 __PACKAGE__->mk_accessors(
-    qw(next_page force_redirect request response session temporary_current_user _current_user _state_variables)
+    qw(next_page force_redirect request response session temporary_current_user)
 );
 
 __PACKAGE__->mk_classdata($_)
@@ -241,24 +241,24 @@
         my $currentuser_obj = shift;
         $self->session->set(
             'user_id' => $currentuser_obj ? $currentuser_obj->id : undef );
-        $self->_current_user( $currentuser_obj || undef );
+        $self->{current_user} = ( $currentuser_obj || undef );
     }
 
     my $object;
 
     if ( defined $self->temporary_current_user ) {
         return $self->temporary_current_user;
-    } elsif ( defined $self->_current_user ) {
-        return $self->_current_user;
+    } elsif ( defined $self->{current_user} ) {
+        return $self->{current_user};
     } elsif ( my $id = $self->session->get('user_id') ) {
-         $object = Jifty->app_class("CurrentUser")->new( id => $id );
+         $object = Jifty->app_class({require => 0}, "CurrentUser")->new( id => $id );
     } elsif ( Jifty->config->framework('AdminMode')) {
-         $object = Jifty->app_class("CurrentUser")->superuser;
+         $object = Jifty->app_class({require => 0}, "CurrentUser")->superuser;
     } else {
-         $object = Jifty->app_class("CurrentUser")->new;
+         $object = Jifty->app_class({require => 0}, "CurrentUser")->new;
     }
     
-    $self->_current_user($object);
+    $self->{current_user} = $object;
     return $object;
 }
 
@@ -354,11 +354,10 @@
         next if $request_action->has_run;
         unless ( $self->request->just_validating ) {
             unless ( Jifty->api->is_allowed( $request_action->class ) ) {
-                $self->log->warn( "Attempt to call denied action '"
+                $self->log->warn( Carp::longmess("Attempt to call denied action '"
                         . $request_action->class
-                        . "'" );
-                Carp::cluck;
-                $self->log->error("NOTICE! A cross-site scripting security fix has been installed so that actions are now by default DENIED during GET requests. You must specifically whitelist safe actions using this in your dispatcher: before '*' => run { Jifty->api->allow('SafeAction') }; - We apologize for the inconvenience.");
+                        . "'" ));
+                $self->log->error("NOTICE! A cross-site scripting security fix has been installed so that actions are now by default DENIED during GET requests. You must specifically whitelist safe actions using this in your dispatcher: before '*' => run { Jifty->api->allow('SafeAction') }; - We apologize for the inconvenience.") if $self->request->request_method eq "GET";
                 push @denied_actions, $request_action;
                 next;
             }
@@ -530,10 +529,9 @@
     # Prepend the base path (probably "App::Action") unless it's there already
     $class = Jifty->api->qualify($class);
 
-    my $loaded = Jifty::Util->require( $class );
     # The implementation class is provided by the client, so this
     # isn't a "shouldn't happen"
-    return unless $loaded;
+    return unless Jifty::Util->require( $class );
 
     my $action;
     # XXX TODO bullet proof
@@ -717,8 +715,8 @@
         my $request = Jifty::Request->new();
         $request->add_state_variable( key => $_->key, value => $_->value )
           for $self->request->state_variables;
-        $request->add_state_variable( key => $_, value => $self->_state_variables->{$_} )
-          for keys %{ $self->_state_variables };
+        $request->add_state_variable( key => $_, value => $self->{state_variables}->{$_} )
+          for keys %{ $self->{state_variables} };
         for (@actions) {
             my $new_action = $request->add_action(
                 moniker   => $_->moniker,
@@ -1248,9 +1246,9 @@
     my $value = shift;
 
     if (!defined($value)) {
-        delete $self->_state_variables->{$name};
+        delete $self->{state_variables}{$name};
     } else {
-        $self->_state_variables->{$name} = $value;
+        $self->{state_variables}{$name} = $value;
     }
 
 }
@@ -1267,7 +1265,7 @@
 
 sub state_variables {
     my $self = shift;
-    return %{ $self->_state_variables };
+    return %{ $self->{state_variables} };
 }
 
 =head3 clear_state_variables
@@ -1279,7 +1277,7 @@
 sub clear_state_variables {
     my $self = shift;
 
-    $self->_state_variables({});
+    $self->{state_variables} = {};
 }
 
 =head2 REGIONS

Modified: jifty/trunk/lib/Jifty/Web/Form/Clickable.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Clickable.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Clickable.pm	Tue Mar 17 11:42:34 2009
@@ -159,8 +159,6 @@
 
     my %args = (
         parameters => {},
-        as_button  => 0,
-        as_link    => 0,
         @_,
     );
 
@@ -170,17 +168,19 @@
     $args{render_as_link}   = delete $args{as_link};
 
     my $self = $class->SUPER::new(
-        {   class          => '',
-            label          => 'Click me!',
-            url            => $root,
-            escape_label   => 1,
-            tooltip        => '',
-            continuation   => Jifty->web->request->continuation,
-            submit         => [],
-            preserve_state => 0,
-            parameters     => {},
+        {   class            => '',
+            label            => 'Click me!',
+            url              => $root,
+            escape_label     => 1,
+            tooltip          => '',
+            continuation     => Jifty->web->request->continuation,
+            submit           => [],
+            preserve_state   => 0,
+            parameters       => {},
+            render_as_button => 0,
+            render_as_link   => 0,
+            %args,
         },
-        \%args
     );
 
     for (qw/continuation call/) {
@@ -222,7 +222,7 @@
 
     # Anything doing fragment replacement needs to preserve the
     # current state as well
-    if ( grep { $self->$_ } $self->handlers or $self->preserve_state ) {
+    if ( grep { $self->$_ } $self->handlers_used or $self->preserve_state ) {
         my %state_vars = Jifty->web->state_variables;
         while ( my ( $key, $val ) = each %state_vars ) {
             if ( $key =~ /^region-(.*?)\.(.*)$/ ) {
@@ -491,7 +491,8 @@
 
 sub _defined_accessor_values {
     my $self = shift;
-    return { map { my $val = $self->$_; defined $val ? ( $_ => $val ) : () }
+    # Note we're walking around Class::Accessor here
+    return { map { my $val = $self->{$_}; defined $val ? ( $_ => $val ) : () }
             $self->SUPER::accessors };
 }
 
@@ -581,25 +582,26 @@
 
 sub generate {
     my $self = shift;
-    for my $trigger ( $self->handlers ) {
+    my $web = Jifty->web;
+    for my $trigger ( $self->handlers_used ) {
         my $value = $self->$trigger;
         next unless $value;
         my @hooks = @{$value};
         for my $hook (@hooks) {
             next unless ref $hook eq "HASH";
             $hook->{region} ||= $hook->{refresh}
-                || Jifty->web->qualified_region;
+                || $web->qualified_region;
 
             my $region
                 = ref $hook->{region}
                 ? $hook->{region}
-                : Jifty->web->get_region( $hook->{region} );
+                : $web->get_region( $hook->{region} );
 
             if ( $hook->{replace_with} ) {
                 my $currently_shown = '';
                 if ($region) {
 
-                    my $state_var = Jifty->web->request->state_variable(
+                    my $state_var = $web->request->state_variable(
                         "region-" . $region->qualified_name );
                     $currently_shown = $state_var->value if ($state_var);
                 }
@@ -611,7 +613,6 @@
                     $self->region_fragment( $hook->{region},
                         "/__jifty/empty" );
 
-#                    Jifty->web->request->remove_state_variable('region-'.$region->qualified_name);
                 } else {
                     $self->region_fragment( $hook->{region},
                         $hook->{replace_with} );
@@ -623,7 +624,7 @@
             if ( $hook->{submit} ) {
                 $self->{submit} ||= [];
                 for my $moniker ( @{ $hook->{submit} } ) {
-                    my $action = Jifty->web->{'actions'}{$moniker};
+                    my $action = $web->{'actions'}{$moniker};
                     $self->register_action($action);
                     $self->parameter( $action->form_field_name($_),
                         $hook->{action_arguments}{$moniker}{$_} )

Modified: jifty/trunk/lib/Jifty/Web/Form/Element.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Element.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Element.pm	Tue Mar 17 11:42:34 2009
@@ -162,10 +162,13 @@
 
 =cut
 
-sub handlers { qw(onclick onchange ondblclick onmousedown onmouseup onmouseover 
-                  onmousemove onmouseout onfocus onblur onkeypress onkeydown 
-                  onkeyup onselect) }
+use constant handlers => qw(
+    onclick onchange ondblclick onmousedown onmouseup onmouseover
+    onmousemove onmouseout onfocus onblur onkeypress onkeydown
+    onkeyup onselect
+);
 
+use constant possible_handlers => { map {($_ => 1)} handlers};
 
 
 =head2 accessors
@@ -176,11 +179,10 @@
 
 =cut
 
-sub accessors { shift->handlers, qw(class title key_binding key_binding_label id label tooltip continuation rel) }
-__PACKAGE__->mk_accessors(qw(_onclick _onchange _ondblclick _onmousedown _onmouseup _onmouseover 
-                             _onmousemove _onmouseout _onfocus _onblur _onkeypress _onkeydown 
-                             _onkeyup _onselect
-                             class title key_binding key_binding_label id label tooltip continuation rel));
+sub accessors { handlers, qw(class title key_binding key_binding_label id label tooltip continuation rel) }
+
+__PACKAGE__->mk_accessors(map "_$_", handlers);
+__PACKAGE__->mk_accessors(qw(class title key_binding key_binding_label id label tooltip continuation rel) );
 
 =head2 new PARAMHASH OVERRIDE
 
@@ -190,22 +192,17 @@
 =cut
 
 sub new {
-    my ($class, $args, $override) = @_;
+    my ($class, $args, $other) = @_;
+    $args = {%{$args}, %{$other || {}}};
     # force using accessor for onclick init
-    for my $trigger ( __PACKAGE__->handlers() ) {
-      if (my $triggerArgs = delete $args->{$trigger}) {
-        $override->{$trigger} = $triggerArgs;
-      }
-    }
+    my $override = {};
+    $override->{$_} = delete $args->{$_}
+        for grep {possible_handlers->{$_} and defined $args->{$_}} keys %{$args};
 
     my $self = $class->SUPER::new($args);
 
-    if ($override) {
-        for my $field ( $self->accessors() ) {
-            # XXX: warn about unexpected ones
-            $self->$field( $override->{$field} ) if exists $override->{$field};
-        }
-    }
+    $self->{handlers_used} = {};
+    $self->$_( $override->{$_} ) for keys %{$override};
 
     return $self;
 }
@@ -311,6 +308,7 @@
     my $trigger = shift;
 
     return $self->$trigger unless @_;
+    $self->{handlers_used}{$trigger} = 1;
 
     my ($arg) = @_;
 
@@ -328,15 +326,13 @@
 
             my @submit_tmp;
             foreach my $submit ( @{$hook->{submit}}) {
-                if (!ref($submit)){ 
-                        push @submit_tmp, $submit;
-                    } 
-                elsif(blessed($submit)) {
-                        push @submit_tmp, $submit->moniker;
-
+                if (!ref($submit)) {
+                    push @submit_tmp, $submit;
+                } elsif(blessed($submit)) {
+                    push @submit_tmp, $submit->moniker;
                 } else { # it's a hashref
-                        push @submit_tmp, $submit->{'action'}->moniker;
-                        $hook->{'action_arguments'}->{ $submit->{'action'}->moniker } = $submit->{'arguments'};
+                    push @submit_tmp, $submit->{'action'}->moniker;
+                    $hook->{'action_arguments'}->{ $submit->{'action'}->moniker } = $submit->{'arguments'};
                 }
 
             }
@@ -364,6 +360,11 @@
 
 }
 
+sub handlers_used {
+    my $self = shift;
+    return keys %{$self->{handlers_used}};
+}
+
 =head2 javascript
 
 Returns the javascript necessary to make the events happen, as a
@@ -390,10 +391,20 @@
     my %response;
 
   HANDLER:
-    for my $trigger ( $self->handlers ) {
-        my $value = $self->$trigger;
+    for my $trigger ( $self->handlers_used ) {
+        # Walk around the Class::Accessor, for speed
+        my $value = $self->{"_$trigger"};
         next unless $value;
 
+        if ( !( $self->handler_allowed($trigger) ) ) {
+            $self->log->error(
+                      "Handler '$trigger' is not supported for field '"
+                    . $self->label
+                    . "' with class "
+                    . ref $self );
+            next;
+        }
+
         my @fragments;
             # if $actions is undef, that means we're submitting _all_ actions in the clickable
             # if $actions is defined but empty, that means we're submitting no actions
@@ -403,19 +414,9 @@
         my $beforeclick;
         my $action_arguments = {};
         for my $hook (grep {ref $_ eq "HASH"} (@{$value})) {
-
-            if (!($self->handler_allowed($trigger))) {
-                $self->log->error("Handler '$trigger' is not supported for field '" . 
-                                  $self->label . 
-                                  "' with class " . ref $self);
-                next HANDLER;
-            }
-
             my %args;
 
             # Submit action
-          
-            
             if ( exists $hook->{submit} ) {
                 $actions = undef;
                 my $disable_form_on_click = exists $hook->{disable} ? $hook->{disable} : 1;
@@ -492,7 +493,7 @@
             push @fragments, \%args;
         }
 
-        my $string = join ";", (grep {not ref $_} (ref $value eq "ARRAY" ? @{$value} : ($value)));
+        my $string = join ";", grep {not ref $_} @{$value};
         if ( @fragments or ( !$actions || %$actions ) ) {
 
             my $update =

Modified: jifty/trunk/lib/Jifty/Web/Form/Field.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Field.pm	Tue Mar 17 11:42:34 2009
@@ -127,7 +127,7 @@
 
 __PACKAGE__->mk_accessors(
     qw(name _label _input_name type sticky sticky_value
-      default_value _action mandatory ajax_validates ajax_canonicalizes
+      default_value mandatory ajax_validates ajax_canonicalizes
       autocompleter preamble hints placeholder focus render_mode
       max_length _element_id disable_autocomplete multiple)
 );
@@ -328,13 +328,13 @@
     my $self = shift;
 
     if (@_) {
-        $self->_action(@_);
+        $self->{action} = shift;
 
         # weaken our circular reference
-        weaken $self->{_action};
+        weaken $self->{action};
     }
 
-    return $self->_action;
+    return $self->{action};
 
 }
 

Modified: jifty/trunk/lib/Jifty/Web/Form/Link.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Link.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Link.pm	Tue Mar 17 11:42:34 2009
@@ -97,11 +97,12 @@
 sub as_string {
     my $self = shift;
     my $label = $self->label;
-    $label = Jifty->web->escape( $label )
+    my $web = Jifty->web;
+    $label = $web->escape( $label )
         if ( $self->escape_label );
 
     my $tooltip = $self->tooltip;
-    $tooltip = Jifty->web->escape( $tooltip )
+    $tooltip = $web->escape( $tooltip )
         if ( defined $tooltip and $self->escape_label );
 
     my $output = '';
@@ -113,13 +114,13 @@
     $output .= (qq( target="@{[$self->target]}")) if $self->target;
     $output .= (qq( accesskey="@{[$self->key_binding]}")) if $self->key_binding;
     $output .= (qq( rel="@{[$self->rel]}"))       if $self->rel;
-    $output .= (qq( href="@{[Jifty->web->escape($self->url)]}"));
+    $output .= (qq( href="@{[$web->escape($self->url)]}"));
     $output .= ( $self->javascript() );
     $output .= (qq(>$label</a>));
 
     $output .= (
         '<script type="text/javascript">' .
-        Jifty->web->escape($self->key_binding_javascript).
+        $web->escape($self->key_binding_javascript).
         "</script>") if $self->key_binding;
 
     return $output;

Modified: jifty/trunk/lib/Jifty/Web/Menu.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Menu.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Menu.pm	Tue Mar 17 11:42:34 2009
@@ -9,7 +9,7 @@
 use Scalar::Util qw(weaken);
 
 __PACKAGE__->mk_accessors(qw(
-    label _parent sort_order link target escape_label class render_children_inline
+    label sort_order link target escape_label class render_children_inline
 ));
 
 =head1 NAME
@@ -60,11 +60,11 @@
 sub parent {
     my $self = shift;
     if (@_) {
-        $self->_parent(@_);
-        weaken $self->{_parent};
+        $self->{parent} = shift;
+        weaken $self->{parent};
     }
 
-    return $self->_parent;
+    return $self->{parent};
 }
 
 
@@ -110,13 +110,12 @@
 
 sub url {
     my $self = shift;
-    $self->{url} = shift if @_;
-
-    $self->{url} = URI->new_abs($self->{url}, $self->parent->url . "/")->as_string
-      if defined $self->{url} and $self->parent and $self->parent->url;
-
-    $self->{url} =~ s!///!/! if $self->{url};
-
+    if (@_) {
+        $self->{url} = shift;
+        $self->{url} = URI->new_abs($self->{url}, $self->parent->url . "/")->as_string
+            if defined $self->{url} and $self->parent and $self->parent->url;
+        $self->{url} =~ s!///!/! if $self->{url};
+    }
     return $self->{url};
 }
 
@@ -154,6 +153,9 @@
     my $proto = ref $self || $self;
 
     if (@_) {
+        # Clear children ordering cache
+        delete $self->{children_list};
+
         $self->{children}{$key} = $proto->new({parent => $self,
                                                sort_order => ($self->{children}{$key}{sort_order}
                                                           || scalar values %{$self->{children}}),
@@ -161,7 +163,6 @@
                                                escape_label => 1,
                                                @_
                                              });
-        Scalar::Util::weaken($self->{children}{$key}{parent});
         
         # Figure out the URL
         my $child = $self->{children}{$key};
@@ -213,6 +214,7 @@
 sub delete {
     my $self = shift;
     my $key = shift;
+    delete $self->{children_list};
     delete $self->{children}{$key};
 }
 
@@ -225,8 +227,14 @@
 
 sub children {
     my $self = shift;
-    my @kids = values %{$self->{children} || {}};
-    @kids = sort {$a->sort_order <=> $b->sort_order} @kids;
+    my @kids;
+    if ($self->{children_list}) {
+        @kids = @{$self->{children_list}};
+    } else {
+        @kids = values %{$self->{children} || {}};
+        @kids = sort {$a->{sort_order} <=> $b->{sort_order}} @kids;
+        $self->{children_list} = \@kids;
+    }
     return wantarray ? @kids : \@kids;
 }
 
@@ -277,14 +285,15 @@
         @_
     );
     my @kids = $self->children;
-    my $id   = Jifty->web->serial;
-    Jifty->web->out( qq{<li class="toplevel }
+    my $web = Jifty->web;
+    my $id   = $web->serial;
+    $web->out( qq{<li class="toplevel }
             . ( $self->active ? 'active' : 'closed' ) .' '.($self->class||"").' '. qq{">}
             . qq{<span class="title">} );
-    Jifty->web->out( $self->as_link );
-    Jifty->web->out(qq{</span>});
+    $web->out( $self->as_link );
+    $web->out(qq{</span>});
     if (@kids) {
-        Jifty->web->out(
+        $web->out(
             qq{<span class="expand"><a href="#" onclick="Jifty.ContextMenu.hideshow('}
                 . $id
                 . qq{'); return false;">&nbsp;</a></span>}
@@ -292,17 +301,17 @@
                 . $id
                 . qq{">} );
         for (@kids) {
-            Jifty->web->out(qq{<li class="submenu }.($_->active ? 'active' : '' ).' '. ($_->class || "").qq{">});
+            $web->out(qq{<li class="submenu }.($_->active ? 'active' : '' ).' '. ($_->class || "").qq{">});
 
             # We should be able to get this as a string.
             # Either stringify the link object or output the label
             # This is really icky. XXX TODO
-            Jifty->web->out( $_->as_link );
-            Jifty->web->out("</li>");
+            $web->out( $_->as_link );
+            $web->out("</li>");
         }
-        Jifty->web->out(qq{</ul>});
+        $web->out(qq{</ul>});
     }
-    Jifty->web->out(qq{</li>});
+    $web->out(qq{</li>});
     '';
 
 }


More information about the Jifty-commit mailing list