[Jifty-commit] r6620 - in jifty/trunk: . lib/Jifty lib/Jifty/Web lib/Jifty/Web/Form
Jifty commits
jifty-commit at lists.jifty.org
Tue Mar 17 11:15:23 EDT 2009
Author: sartak
Date: Tue Mar 17 11:15:22 2009
New Revision: 6620
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:
Modified: jifty/trunk/lib/Jifty/CurrentUser.pm
==============================================================================
--- jifty/trunk/lib/Jifty/CurrentUser.pm (original)
+++ jifty/trunk/lib/Jifty/CurrentUser.pm Tue Mar 17 11:15:22 2009
@@ -77,9 +77,8 @@
my %args = (@_);
# Duck-typing to check to for a user class
- 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));
+ if (keys %args and UNIVERSAL::can(Jifty->app_class('Model', 'User'), 'new') ) {
+ $self->user_object(Jifty->app_class('Model', 'User')->new(current_user => $self));
$self->user_object->load_by_cols(%args);
}
@@ -138,14 +137,16 @@
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
- return $self->{user_object}->id if $self->{user_object};
-
+ if ($self->user_object) {
+ return ($self->user_object->id());
+ }
+
# No user object, return a null ID
- return 0;
+ else {
+ 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:15:22 2009
@@ -286,9 +286,8 @@
>;
our $Dispatcher;
-our $Request;
-sub request { $Request }
+sub request { Jifty->web->request }
sub _ret (@);
sub under ($$@) { _ret @_ } # partial match at beginning of path component
sub before ($$@) { _ret @_ } # exact match on the path component
@@ -305,9 +304,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 ($@);
@@ -484,10 +483,9 @@
# 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 = $Request->path;
+ my $path = Jifty->web->request->path;
utf8::downgrade($path); # Mason handle non utf8 path.
$Dispatcher->_do_dispatch( $path );
};
@@ -810,21 +808,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]
@@ -921,8 +919,9 @@
elsif ( ref($cond) eq 'HASH' ) {
local $@;
my $rv = eval {
- for my $key ( sort grep {length} keys %$cond )
+ for my $key ( sort keys %$cond )
{
+ next if $key eq '';
my $meth = "_match_$key";
$self->$meth( $cond->{$key} ) or return;
}
@@ -958,7 +957,7 @@
sub _match_method {
my ( $self, $method ) = @_;
#$self->log->debug("Matching method ".request->request_method." against ".$method);
- $Request->request_method eq uc($method);
+ lc( request->request_method ) eq lc($method);
}
=head2 _match_https
@@ -1256,8 +1255,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?
@@ -1280,8 +1279,9 @@
Jifty->web->_redirect( "/errors/500?J:C=" . $c->id );
} elsif ($err) {
Jifty->handler->buffer->pop while Jifty->handler->buffer->depth > $start_depth;
- $self->_abort;
+ die $err;
}
+
}
Modified: jifty/trunk/lib/Jifty/Everything.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Everything.pm (original)
+++ jifty/trunk/lib/Jifty/Everything.pm Tue Mar 17 11:15:22 2009
@@ -40,8 +40,6 @@
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:15:22 2009
@@ -85,11 +85,6 @@
$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:15:22 2009
@@ -58,9 +58,7 @@
=cut
-my $SUPERUSER;
-sub current_user { return $SUPERUSER ||= Jifty->app_class('CurrentUser')->superuser }
-sub current_user_can {return 1;}
+sub current_user { return Jifty->app_class('CurrentUser')->superuser }
=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:15:22 2009
@@ -79,8 +79,9 @@
my $x = (CORE::caller( $depth++ ))[0];
my $caller_self = $DB::args[0];
next unless ref($caller_self); #skip class methods;
- next unless my $s = $caller_self->can('current_user');
- next unless my $t = $s->($caller_self);
+ next if $caller_self->isa('Jifty::Date');
+ next unless $caller_self->can('current_user');
+ next unless my $t = $caller_self->current_user;
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:15:22 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({require => 0}, 'Plugin');
+ my $app_plugin_root = Jifty->app_class('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:15:22 2009
@@ -118,7 +118,7 @@
my ($cgi) = @_;
# Store away request method
- $self->request_method( uc $cgi->request_method );
+ $self->request_method( $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:15:22 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)
+ qw(next_page force_redirect request response session temporary_current_user _current_user _state_variables)
);
__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({require => 0}, "CurrentUser")->new( id => $id );
+ $object = Jifty->app_class("CurrentUser")->new( id => $id );
} elsif ( Jifty->config->framework('AdminMode')) {
- $object = Jifty->app_class({require => 0}, "CurrentUser")->superuser;
+ $object = Jifty->app_class("CurrentUser")->superuser;
} else {
- $object = Jifty->app_class({require => 0}, "CurrentUser")->new;
+ $object = Jifty->app_class("CurrentUser")->new;
}
- $self->{current_user} = $object;
+ $self->_current_user($object);
return $object;
}
@@ -354,10 +354,11 @@
next if $request_action->has_run;
unless ( $self->request->just_validating ) {
unless ( Jifty->api->is_allowed( $request_action->class ) ) {
- $self->log->warn( Carp::longmess("Attempt to call denied action '"
+ $self->log->warn( "Attempt to call denied action '"
. $request_action->class
- . "'" ));
- $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";
+ . "'" );
+ 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.");
push @denied_actions, $request_action;
next;
}
@@ -529,9 +530,10 @@
# 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 Jifty::Util->require( $class );
+ return unless $loaded;
my $action;
# XXX TODO bullet proof
@@ -715,8 +717,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,
@@ -1246,9 +1248,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;
}
}
@@ -1265,7 +1267,7 @@
sub state_variables {
my $self = shift;
- return %{ $self->{state_variables} };
+ return %{ $self->_state_variables };
}
=head3 clear_state_variables
@@ -1277,7 +1279,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:15:22 2009
@@ -159,6 +159,8 @@
my %args = (
parameters => {},
+ as_button => 0,
+ as_link => 0,
@_,
);
@@ -168,19 +170,17 @@
$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 => {},
- render_as_button => 0,
- render_as_link => 0,
- %args,
+ { class => '',
+ label => 'Click me!',
+ url => $root,
+ escape_label => 1,
+ tooltip => '',
+ continuation => Jifty->web->request->continuation,
+ submit => [],
+ preserve_state => 0,
+ parameters => {},
},
+ \%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_used or $self->preserve_state ) {
+ if ( grep { $self->$_ } $self->handlers or $self->preserve_state ) {
my %state_vars = Jifty->web->state_variables;
while ( my ( $key, $val ) = each %state_vars ) {
if ( $key =~ /^region-(.*?)\.(.*)$/ ) {
@@ -491,8 +491,7 @@
sub _defined_accessor_values {
my $self = shift;
- # Note we're walking around Class::Accessor here
- return { map { my $val = $self->{$_}; defined $val ? ( $_ => $val ) : () }
+ return { map { my $val = $self->$_; defined $val ? ( $_ => $val ) : () }
$self->SUPER::accessors };
}
@@ -582,26 +581,25 @@
sub generate {
my $self = shift;
- my $web = Jifty->web;
- for my $trigger ( $self->handlers_used ) {
+ for my $trigger ( $self->handlers ) {
my $value = $self->$trigger;
next unless $value;
my @hooks = @{$value};
for my $hook (@hooks) {
next unless ref $hook eq "HASH";
$hook->{region} ||= $hook->{refresh}
- || $web->qualified_region;
+ || Jifty->web->qualified_region;
my $region
= ref $hook->{region}
? $hook->{region}
- : $web->get_region( $hook->{region} );
+ : Jifty->web->get_region( $hook->{region} );
if ( $hook->{replace_with} ) {
my $currently_shown = '';
if ($region) {
- my $state_var = $web->request->state_variable(
+ my $state_var = Jifty->web->request->state_variable(
"region-" . $region->qualified_name );
$currently_shown = $state_var->value if ($state_var);
}
@@ -613,6 +611,7 @@
$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} );
@@ -624,7 +623,7 @@
if ( $hook->{submit} ) {
$self->{submit} ||= [];
for my $moniker ( @{ $hook->{submit} } ) {
- my $action = $web->{'actions'}{$moniker};
+ my $action = Jifty->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:15:22 2009
@@ -162,13 +162,10 @@
=cut
-use constant handlers => qw(
- onclick onchange ondblclick onmousedown onmouseup onmouseover
- onmousemove onmouseout onfocus onblur onkeypress onkeydown
- onkeyup onselect
-);
+sub 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
@@ -179,10 +176,11 @@
=cut
-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) );
+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));
=head2 new PARAMHASH OVERRIDE
@@ -192,17 +190,22 @@
=cut
sub new {
- my ($class, $args, $other) = @_;
- $args = {%{$args}, %{$other || {}}};
+ my ($class, $args, $override) = @_;
# force using accessor for onclick init
- my $override = {};
- $override->{$_} = delete $args->{$_}
- for grep {possible_handlers->{$_} and defined $args->{$_}} keys %{$args};
+ for my $trigger ( __PACKAGE__->handlers() ) {
+ if (my $triggerArgs = delete $args->{$trigger}) {
+ $override->{$trigger} = $triggerArgs;
+ }
+ }
my $self = $class->SUPER::new($args);
- $self->{handlers_used} = {};
- $self->$_( $override->{$_} ) for keys %{$override};
+ if ($override) {
+ for my $field ( $self->accessors() ) {
+ # XXX: warn about unexpected ones
+ $self->$field( $override->{$field} ) if exists $override->{$field};
+ }
+ }
return $self;
}
@@ -308,7 +311,6 @@
my $trigger = shift;
return $self->$trigger unless @_;
- $self->{handlers_used}{$trigger} = 1;
my ($arg) = @_;
@@ -326,13 +328,15 @@
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'};
}
}
@@ -360,11 +364,6 @@
}
-sub handlers_used {
- my $self = shift;
- return keys %{$self->{handlers_used}};
-}
-
=head2 javascript
Returns the javascript necessary to make the events happen, as a
@@ -391,20 +390,10 @@
my %response;
HANDLER:
- for my $trigger ( $self->handlers_used ) {
- # Walk around the Class::Accessor, for speed
- my $value = $self->{"_$trigger"};
+ for my $trigger ( $self->handlers ) {
+ 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
@@ -414,9 +403,19 @@
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;
@@ -493,7 +492,7 @@
push @fragments, \%args;
}
- my $string = join ";", grep {not ref $_} @{$value};
+ my $string = join ";", (grep {not ref $_} (ref $value eq "ARRAY" ? @{$value} : ($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:15:22 2009
@@ -127,7 +127,7 @@
__PACKAGE__->mk_accessors(
qw(name _label _input_name type sticky sticky_value
- default_value mandatory ajax_validates ajax_canonicalizes
+ default_value _action 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} = shift;
+ $self->_action(@_);
# 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:15:22 2009
@@ -97,12 +97,11 @@
sub as_string {
my $self = shift;
my $label = $self->label;
- my $web = Jifty->web;
- $label = $web->escape( $label )
+ $label = Jifty->web->escape( $label )
if ( $self->escape_label );
my $tooltip = $self->tooltip;
- $tooltip = $web->escape( $tooltip )
+ $tooltip = Jifty->web->escape( $tooltip )
if ( defined $tooltip and $self->escape_label );
my $output = '';
@@ -114,13 +113,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="@{[$web->escape($self->url)]}"));
+ $output .= (qq( href="@{[Jifty->web->escape($self->url)]}"));
$output .= ( $self->javascript() );
$output .= (qq(>$label</a>));
$output .= (
'<script type="text/javascript">' .
- $web->escape($self->key_binding_javascript).
+ Jifty->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:15:22 2009
@@ -9,7 +9,7 @@
use Scalar::Util qw(weaken);
__PACKAGE__->mk_accessors(qw(
- label sort_order link target escape_label class render_children_inline
+ label _parent sort_order link target escape_label class render_children_inline
));
=head1 NAME
@@ -60,11 +60,11 @@
sub parent {
my $self = shift;
if (@_) {
- $self->{parent} = shift;
- weaken $self->{parent};
+ $self->_parent(@_);
+ weaken $self->{_parent};
}
- return $self->{parent};
+ return $self->_parent;
}
@@ -110,12 +110,13 @@
sub url {
my $self = shift;
- 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};
- }
+ $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};
+
return $self->{url};
}
@@ -153,9 +154,6 @@
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}}),
@@ -163,6 +161,7 @@
escape_label => 1,
@_
});
+ Scalar::Util::weaken($self->{children}{$key}{parent});
# Figure out the URL
my $child = $self->{children}{$key};
@@ -214,7 +213,6 @@
sub delete {
my $self = shift;
my $key = shift;
- delete $self->{children_list};
delete $self->{children}{$key};
}
@@ -227,14 +225,8 @@
sub children {
my $self = shift;
- 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;
- }
+ my @kids = values %{$self->{children} || {}};
+ @kids = sort {$a->sort_order <=> $b->sort_order} @kids;
return wantarray ? @kids : \@kids;
}
@@ -285,15 +277,14 @@
@_
);
my @kids = $self->children;
- my $web = Jifty->web;
- my $id = $web->serial;
- $web->out( qq{<li class="toplevel }
+ my $id = Jifty->web->serial;
+ Jifty->web->out( qq{<li class="toplevel }
. ( $self->active ? 'active' : 'closed' ) .' '.($self->class||"").' '. qq{">}
. qq{<span class="title">} );
- $web->out( $self->as_link );
- $web->out(qq{</span>});
+ Jifty->web->out( $self->as_link );
+ Jifty->web->out(qq{</span>});
if (@kids) {
- $web->out(
+ Jifty->web->out(
qq{<span class="expand"><a href="#" onclick="Jifty.ContextMenu.hideshow('}
. $id
. qq{'); return false;"> </a></span>}
@@ -301,17 +292,17 @@
. $id
. qq{">} );
for (@kids) {
- $web->out(qq{<li class="submenu }.($_->active ? 'active' : '' ).' '. ($_->class || "").qq{">});
+ Jifty->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
- $web->out( $_->as_link );
- $web->out("</li>");
+ Jifty->web->out( $_->as_link );
+ Jifty->web->out("</li>");
}
- $web->out(qq{</ul>});
+ Jifty->web->out(qq{</ul>});
}
- $web->out(qq{</li>});
+ Jifty->web->out(qq{</li>});
'';
}
More information about the Jifty-commit
mailing list