[Jifty-commit] r1583 - in jifty/branches/moose: . lib/Jifty
lib/Jifty/Web lib/Jifty/Web/Form/Field
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Jul 14 23:23:14 EDT 2006
Author: audreyt
Date: Fri Jul 14 23:23:13 2006
New Revision: 1583
Modified:
jifty/branches/moose/Makefile.PL
jifty/branches/moose/lib/Jifty/Web.pm
jifty/branches/moose/lib/Jifty/Web/Form.pm
jifty/branches/moose/lib/Jifty/Web/Form/Clickable.pm
jifty/branches/moose/lib/Jifty/Web/Form/Element.pm
jifty/branches/moose/lib/Jifty/Web/Form/Field.pm
jifty/branches/moose/lib/Jifty/Web/Form/Field/Button.pm
jifty/branches/moose/lib/Jifty/Web/Form/Field/Checkbox.pm
jifty/branches/moose/lib/Jifty/Web/Form/Field/Textarea.pm
jifty/branches/moose/lib/Jifty/Web/Form/Link.pm
jifty/branches/moose/lib/Jifty/Web/Menu.pm
Log:
* Class::Accessor now goes away.
Modified: jifty/branches/moose/Makefile.PL
==============================================================================
--- jifty/branches/moose/Makefile.PL (original)
+++ jifty/branches/moose/Makefile.PL Fri Jul 14 23:23:13 2006
@@ -6,7 +6,6 @@
requires('App::CLI' => 0.03 ); # App::CLI::Command::Help App::CLI::Command
requires('Cache::Cache'); #Cache::FileCache
requires('Calendar::Simple');
-requires('Class::Accessor'); # Class::Accessor::Fast
requires('Class::Accessor::Named');
requires('Class::Container');
requires('Class::Data::Inheritable');
Modified: jifty/branches/moose/lib/Jifty/Web.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web.pm Fri Jul 14 23:23:13 2006
@@ -16,7 +16,7 @@
use XML::Writer;
use CSS::Squish;
use Digest::MD5 qw(md5_hex);
-use base qw/Class::Accessor::Fast Class::Data::Inheritable Jifty::Object/;
+use base qw/Class::Data::Inheritable Jifty::Object/;
use vars qw/$SERIAL @JS_INCLUDES/;
use Moose;
Modified: jifty/branches/moose/lib/Jifty/Web/Form.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Form.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Form.pm Fri Jul 14 23:23:13 2006
@@ -3,7 +3,7 @@
package Jifty::Web::Form;
-use base qw/Jifty::Object Class::Accessor::Fast/;
+use base qw/Jifty::Object/;
use Moose;
has actions => qw( is rw isa Any );
Modified: jifty/branches/moose/lib/Jifty/Web/Form/Clickable.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Form/Clickable.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Form/Clickable.pm Fri Jul 14 23:23:13 2006
@@ -23,13 +23,18 @@
=cut
-sub accessors {
- shift->SUPER::accessors,
- qw(url escape_label tooltip continuation call returns submit preserve_state render_as_button render_as_link);
-}
-__PACKAGE__->mk_accessors(
- qw(url escape_label tooltip continuation call returns submit preserve_state render_as_button render_as_link)
-);
+use Moose;
+has url => qw( is rw isa Str );
+has escape_label => qw( is rw isa Bool );
+has tooltip => qw( is rw isa Str );
+has continuation => qw( is rw isa Any ); # Jifty::Continuation | Str
+has call => qw( is rw isa Any ); # Jifty::Continuation | Str
+has returns => qw( is rw isa HashRef );
+has submit => qw( is rw isa ArrayRef );
+has preserve_state => qw( is rw isa Str );
+has render_as_button => qw( is rw isa Str );
+has render_as_link => qw( is rw isa Str );
+no Moose;
=head2 new PARAMHASH
@@ -166,7 +171,8 @@
}
}
- for my $field ( $self->accessors() ) {
+ for my $attr ( $self->meta->compute_all_applicable_attributes ) {
+ my $field = $attr->name;
$self->$field( $args{$field} ) if exists $args{$field};
}
@@ -430,8 +436,13 @@
sub _defined_accessor_values {
my $self = shift;
- return { map { my $val = $self->$_; defined $val ? ($_ => $val) : () }
- $self->SUPER::accessors };
+ my @superclasses = $self->meta->superclasses;
+ my @attrs = map { $_->meta->compute_all_applicable_attributes } @superclasses;
+ return { map {
+ my $name = $_->name;
+ my $val = $self->$name;
+ defined $val ? ($name => $val) : ()
+ } @attrs };
}
=head2 as_link
Modified: jifty/branches/moose/lib/Jifty/Web/Form/Element.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Form/Element.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Form/Element.pm Fri Jul 14 23:23:13 2006
@@ -105,9 +105,18 @@
=cut
-use base qw/Jifty::Object Class::Accessor::Fast/;
+use base qw/Jifty::Object/;
use Jifty::JSON;
+use Moose;
+has onclick => qw( is rw isa Any );
+has class => qw( is rw isa Str default ) => '';
+has key_binding => qw( is rw isa Str );
+has id => qw( is rw isa Str );
+has label => qw( is rw isa Str );
+has tooltip => qw( is rw isa Str );
+no Moose;
+
=head2 handlers
Currently, the only supported event handlers are C<onclick>.
@@ -119,17 +128,6 @@
sub handlers { qw(onclick); }
-=head2 accessors
-
-Any descendant of L<Jifty::Web::Form::Element> should be able to
-accept any of the event handlers (above) as one of the keys to its
-C<new> parameter hash.
-
-=cut
-
-sub accessors { shift->handlers, qw(class key_binding id label tooltip) }
-__PACKAGE__->mk_accessors(qw(onclick class key_binding id label tooltip));
-
=head2 javascript
Returns the javascript necessary to make the events happen.
Modified: jifty/branches/moose/lib/Jifty/Web/Form/Field.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Form/Field.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Form/Field.pm Fri Jul 14 23:23:13 2006
@@ -1,28 +1,38 @@
-=begin properties
-
-constructor
-canonicalizer
-available_values
-ajax_validates
-autocompleter
-
-default_value
-valid_values
-validator
-render_as
-label
-hints
-length
-mandatory
-
-=end properties
-
-=cut
-
use warnings;
use strict;
package Jifty::Web::Form::Field;
+use Moose;
+has name => qw( is rw isa Str );
+has label => qw( is rw isa Str lazy 1 default ) => sub {
+ my $self = shift;
+ return $self->name;
+};
+has input_name => qw( is rw isa Str lazy 1 default ) => sub {
+ my $self = shift;
+ my $action = $self->action;
+ return $action ? $self->action->form_field_name( $self->name )
+ : '';
+};
+has type => qw( is rw isa Str default text );
+has sticky => qw( is rw isa Str );
+has sticky_value => qw( is rw isa Any );
+has default_value => qw( is rw isa Any );
+has action => qw( is rw isa Any weak_ref 1 );
+has mandatory => qw( is rw isa Str );
+has ajax_validates => qw( is rw isa Str );
+has ajax_canonicalizes => qw( is rw isa Str );
+has autocompleter => qw( is rw isa CodeRef );
+has preamble => qw( is rw isa Str );
+has hints => qw( is rw isa Str );
+has render_mode => qw( is rw isa Str default update );
+has length => qw( is rw isa Str );
+has element_id => qw( is rw isa Str lazy 1 default ) => sub {
+ my $self = shift;
+ return $self->input_name."-".Jifty->web->serial;
+};
+no Moose;
+
=head1 NAME
@@ -47,32 +57,28 @@
use HTML::Entities;
use overload '""' => sub { shift->render}, bool => sub { 1 };
-=head2 new
+=head2 accessors
+
+Lists the accessors that are able to be called from within a call to
+C<new>. Subclasses should extend this list.
+
+=cut
+
+=head2 BUILD
Creates a new L<Jifty::Web::Form::Field> (possibly magically blessing into a subclass).
Should only be called from C<< $action->arguments >>.
=cut
-sub new {
- my $class = shift;
- my $self = $class->SUPER::new(
- { type => 'text',
- class => '',
- input_name => '',
- default_value => '',
- sticky_value => '',
- render_mode => 'update' });
+sub BUILD {
+ my $self = shift;
my $args = ref($_[0]) ? $_[0] : {@_};
my $subclass = ucfirst($args->{render_as} || $args->{type} || 'text');
$subclass = 'Jifty::Web::Form::Field::' . $subclass unless $subclass =~ /::/;
bless $self, $subclass if Jifty::Util->require($subclass);
- for my $field ( $self->accessors() ) {
- $self->$field( $args->{$field} ) if exists $args->{$field};
- }
-
# If they key and/or value imply that this argument is going to be
# a mapped argument, then do the mapping and mark the field as hidden.
my ($key, $value) = Jifty::Request::Mapper->query_parameters($self->input_name, $self->current_value);
@@ -93,16 +99,6 @@
}
-=head2 accessors
-
-Lists the accessors that are able to be called from within a call to
-C<new>. Subclasses should extend this list.
-
-=cut
-
-sub accessors { shift->SUPER::accessors(), qw(name label input_name type sticky sticky_value default_value action mandatory ajax_validates ajax_canonicalizes autocompleter preamble hints render_mode length _element_id); }
-__PACKAGE__->mk_accessors(qw(name _label _input_name type sticky sticky_value default_value _action mandatory ajax_validates ajax_canonicalizes autocompleter preamble hints render_mode length _element_id));
-
=head2 name [VALUE]
Gets or sets the name of the field. This is seperate from the name of
@@ -177,22 +173,6 @@
=cut
-sub input_name {
- my $self = shift;
-
-# If we've been explicitly handed a name, we should run with it.
-# Otherwise, we should ask our action, how to turn our "name"
-# into a form input name.
-
- my $ret = $self->_input_name(@_);
- return $ret if $ret;
-
- my $action = $self->action;
- return $action ? $self->action->form_field_name( $self->name )
- : '';
-}
-
-
=head2 fallback_name
Return the form field's fallback name. This should be used to create a
@@ -226,14 +206,6 @@
=cut
-sub label {
- my $self = shift;
- my $val = $self->_label(@_);
- defined $val ? $val : $self->name;
-
-}
-
-
=head2 element_id
Returns a unique C<id> attribute for this field based on the field name. This is
@@ -242,11 +214,6 @@
=cut
-sub element_id {
- my $self = shift;
- return $self->_element_id || $self->_element_id( $self->input_name ."-".Jifty->web->serial);
-}
-
=head2 action [VALUE]
Gets or sets the L<Jifty::Action> object that this
@@ -256,16 +223,6 @@
=cut
-sub action {
- my $self = shift;
- my $action = $self->_action(@_);
-
- # If we're setting the action, we need to weaken
- # the reference to not get caught in a loop
- Scalar::Util::weaken( $self->{_action} ) if @_;
- return $action;
-}
-
=head2 current_value
Gets the current value we should be using for this form field.
Modified: jifty/branches/moose/lib/Jifty/Web/Form/Field/Button.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Form/Field/Button.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Form/Field/Button.pm Fri Jul 14 23:23:13 2006
@@ -4,7 +4,10 @@
package Jifty::Web::Form::Field::Button;
use base qw/Jifty::Web::Form::Field/;
-__PACKAGE__->mk_accessors(qw/button_as_link/);
+
+use Moose;
+has button_as_link => qw( is rw isa Bool );
+no Moose;
=head2 accessors
@@ -14,8 +17,6 @@
=cut
-sub accessors { shift->SUPER::accessors(), 'button_as_link' }
-
=head2 render_widget
Renders the button widget.
Modified: jifty/branches/moose/lib/Jifty/Web/Form/Field/Checkbox.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Form/Field/Checkbox.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Form/Field/Checkbox.pm Fri Jul 14 23:23:13 2006
@@ -4,7 +4,10 @@
package Jifty::Web::Form::Field::Checkbox;
use base qw/Jifty::Web::Form::Field/;
-__PACKAGE__->mk_accessors(qw/checked value/);
+use Moose;
+has checked => qw( is rw isa Bool );
+has value => qw( is rw isa Str );
+no Moose;
=head2 accessors
@@ -14,8 +17,6 @@
=cut
-sub accessors { shift->SUPER::accessors(), 'checked' , 'value' }
-
=head2 render_widget
Renders the checkbox widget.
Modified: jifty/branches/moose/lib/Jifty/Web/Form/Field/Textarea.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Form/Field/Textarea.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Form/Field/Textarea.pm Fri Jul 14 23:23:13 2006
@@ -5,7 +5,10 @@
use base qw/Jifty::Web::Form::Field/;
-__PACKAGE__->mk_accessors(qw(rows cols));
+use Moose;
+has rows => qw( is rw isa Int );
+has cols => qw( is rw isa Int );
+no Moose;
=head2 accessors
@@ -14,8 +17,6 @@
=cut
-sub accessors { shift->SUPER::accessors(), 'rows', 'cols' }
-
=head2 render_widget
Renders the textarea widget.
Modified: jifty/branches/moose/lib/Jifty/Web/Form/Link.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Form/Link.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Form/Link.pm Fri Jul 14 23:23:13 2006
@@ -15,10 +15,17 @@
=cut
+use Moose;
+has url => qw( is rw isa Str lazy 1 default ) => sub { $ENV{PATH_INFO} };
+has escape_label => qw( is rw isa Bool default 1 );
+has tooltip => qw( is rw isa Str );
+has target => qw( is rw isa Str );
+no Moose;
+
use base 'Jifty::Web::Form::Element';
# Since we don't inherit from Form::Field, we don't otherwise stringify
-use overload '""' => sub { shift->render}, bool => sub { 1 };
+use overload '""' => sub { shift->render }, bool => sub { 1 };
=head2 accessors
@@ -28,9 +35,6 @@
=cut
-sub accessors { shift->SUPER::accessors(), qw(url escape_label tooltip target); }
-__PACKAGE__->mk_accessors(qw(url escape_label tooltip target));
-
=head2 new PARAMHASH
Creates a new L<Jifty::Web::Form::Link> object. Possible arguments to
@@ -63,24 +67,6 @@
=cut
-sub new {
- my $class = shift;
- my $self = $class->SUPER::new(
- { url => $ENV{PATH_INFO},
- label => "Click me!",
- tooltip => undef,
- escape_label => 1,
- class => '',
- target => '' }
- );
- my $args = ref($_[0]) ? $_[0] : {@_};
-
- for my $field ( keys %$args ) {
- $self->$field( $args->{$field} );
- }
-
- return $self;
-}
=head2 url [URL]
Modified: jifty/branches/moose/lib/Jifty/Web/Menu.pm
==============================================================================
--- jifty/branches/moose/lib/Jifty/Web/Menu.pm (original)
+++ jifty/branches/moose/lib/Jifty/Web/Menu.pm Fri Jul 14 23:23:13 2006
@@ -1,15 +1,15 @@
package Jifty::Web::Menu;
-use URI;
-
use Moose;
has label => qw( is rw isa Str );
-has parent => qw( is rw isa Jifty::Web::Menu );
+has parent => qw( is rw isa Jifty::Web::Menu weak_ref 1 );
has sort_order => qw( is rw isa Int );
-has link => qw( is rw isa Jifty::Web::Link );
+has link => qw( is rw isa Any ); # Jifty::Web::Link;
has escape_label => qw( is rw isa Bool );
no Moose;
+use URI;
+
=head2 new PARAMHASH
Creates a new L<Jifty::Web::Menu> object. Possible keys in the
@@ -22,8 +22,7 @@
sub new {
my $package = shift;
# Class::Accessor only wants a hashref;
- $package->SUPER::new( ref($_[0]) eq 'HASH' ? @_ : {@_} );
-
+ $package->meta->new_object( ref($_[0]) eq 'HASH' ? %{$_[0]} : @_ );
}
More information about the Jifty-commit
mailing list