=cut
-sub debug { 0 }
+sub debug { 0 }
=item config
=item setup
- My::App->setup($data_source, $user, $password, \%attr);
-
-Initialise the Maypole application and plugins and model classes - see
-L<Maypole::Manual::Plugins>.
-
-If your model is based on L<Maypole::Model::CDBI>, the C<\%attr> hashref can
-contain options that are passed directly to L<Class::DBI::Loader>, to control
-how the model hierarchy is constructed.
+ My::App->setup($data_source, $user, $password, \%attr);
+Initialise the Maypole application and plugins and model classes.
Your application should call this B<after> setting up configuration data via
L<"config">.
+It calls the hook C<setup_model> to setup the model. The %attr hash contains
+options and arguments used to set up the model. See the particular model's
+documentation. However here is the most usage of setup where
+Maypole::Model::CDBI is the base class.
+
+ My::App->setup($data_source, $user, $password,
+ { opitons => { # These are DB connection options
+ AutoCommit => 0,
+ RaiseError => 1,
+ ...
+ },
+ # These are Class::DBI::Loader arguments.
+ relationships => 1,
+ ...
+ }
+ );
+
+Also, see L<Maypole::Manual::Plugins>.
+
=cut
+
sub setup
{
my $class = shift;
It inherits accessor and helper methods from L<Maypole::Model::Base>.
+When specified as the application model, it will use Class::DBI::Loader
+to generate the model classes from the provided database. If you do not
+wish to use this functionality, use L<Maypole::Model::CDBI::Plain> which
+will instead use Class::DBI classes provided.
+
=cut
use base qw(Maypole::Model::Base Class::DBI);
Action methods are methods that are accessed through web (or other public) interface.
-=item do_edit
+=head2 do_edit
If there is an object in C<$r-E<gt>objects>, then it should be edited
with the parameters in C<$r-E<gt>params>; otherwise, a new object should
=head2 stringify_column
+ Returns the name of the column to use when stringifying
+ and object.
+
=cut
sub stringify_column {
=head2 do_pager
+ Sets the pager template argument ($r->{template_args}{pager})
+ to a Class::DBI::Pager object based on the rows_per_page
+ value set in the configuration of the application.
+
+ This pager is used via the pager macro in TT Templates, and
+ is also accessible via Mason.
+
=cut
sub do_pager {
=head2 order
+ Returns the SQL order syntax based on the order parameter passed
+ to the request, and the valid columns.. i.e. 'title ASC' or 'date_created DESC'.
+
+ $sql .= $self->order($r);
+
+ If the order column is not a column of this table,
+ or an order argument is not passed, then the return value is undefined.
+
+ Note: the returned value does not start with a space.
+
=cut
sub order {
return $order;
}
+=head2 setup
+
+ This method is inherited from Maypole::Model::Base and calls setup_database,
+ which uses Class::DBI::Loader to create and load Class::DBI classes from
+ the given database schema.
+
+=cut
+
=head2 setup_database
+The $opts argument is a hashref of options. The "options" key is a hashref of
+Database connection options . Other keys may be various Loader arguments or
+flags. It has this form:
+ {
+ # DB connection options
+ options { AutoCommit => 1 , ... },
+ # Loader args
+ relationships => 1,
+ ...
+ }
+
=cut
sub setup_database {
_select_guts unselect_element search_inputs make_param_foreign
);
-our $VERSION = '.09';
-
-# 11-05-05 - added _to_link_hidden to make a link to the hidden object
-# - fixed _to_hidden when called with no args. Hides self obj.
-# 11-04-05 - _to_textfield: tries to call "deflate4edit" if column is has_a
-# 11-08-05 - Changed Version to .08
-
-
-
-# 1-10-06 -- fixed bug in to_textfiled that was stringifyingf CDBI objects
-# #
-#
-# 1-20-06 - to_select - call db_Main with has a class.
-# 1-24-06 - to_select_from_many now named _to_select_from_many . Old deprecated
-# - hasmany_class removed in favor of model's related_class method.
-# - took out do_select. That is a model action.
-# - use search_columns instead of search_fields now.
-# - use to_field('column', 'select', {args}) instead of a_select_box.
-# -- took out make_hidden_element.was my own personal hack
-# -- added _box from DH's FormView to calculate decent textarea size
-# -- Refactor to_field into _from_* method calls.
-#
-# 1-25-06 -- Added _to_checkbox and _to_radio from FView
-# 1-27-06 -- Refactored into yet more exported methods
-# 1-28-06 -- select constraints where, join order by
-
+our $VERSION = '2.11';
=head1 NAME
=cut
sub _field_from_column {
- my ($self, $field, $args) = @_;
- my $class = ref $self || $self;
- # Get column type
- unless ($args->{column_type}) {
- if ($class->can('column_type')) {
- $args->{column_type} = $class->column_type($field);
- }
- else {
- # Right, have some of this
- eval "package $class; Class::DBI::Plugin::Type->import()";
- $args->{column_type} = $class->column_type($field);
- }
+ my ($self, $field, $args) = @_;
+ my $class = ref $self || $self;
+ # Get column type
+ unless ($args->{column_type}) {
+ if ($class->can('column_type')) {
+ $args->{column_type} = $class->column_type($field);
+ } else {
+ # Right, have some of this
+ eval "package $class; Class::DBI::Plugin::Type->import()";
+ $args->{column_type} = $class->column_type($field);
}
- my $type = $args->{column_type};
-
- return $self->_to_textfield($field)
- if $type and $type =~ /(VAR)?CHAR/i; #common type
- return $self->_to_textarea($field, $args)
- if $type and $type =~ /^(TEXT|BLOB)$/i;
- return $self->_to_enum_select($field, $args)
- if $type and $type =~ /^ENUM\((.*?)\)$/i;
- return $self->_to_bool_select($field, $args)
- if $type and $type =~ /^BOOL/i;
- return $self->_to_readonly($field, $args)
- if $type and $type =~ /^readonly$/i;
- return;
+ }
+ my $type = $args->{column_type};
+
+ return $self->_to_textfield($field)
+ if $type and $type =~ /(VAR)?CHAR/i; #common type
+ return $self->_to_textarea($field, $args)
+ if $type and $type =~ /^(TEXT|BLOB)$/i;
+ return $self->_to_enum_select($field, $args)
+ if $type and $type =~ /^ENUM\((.*?)\)$/i;
+ return $self->_to_bool_select($field, $args)
+ if $type and $type =~ /^BOOL/i;
+ return $self->_to_readonly($field, $args)
+ if $type and $type =~ /^readonly$/i;
+ return;
}
my $fclass = $args->{class} || '';
my $stringify = $args->{stringify} || '';
my @res;
- for (@$items) {
- my $val = $_->{$pk};
+ for my $item (@$items) {
+ my $val = $item->{$pk};
my $opt = HTML::Element->new("option", value => $val );
$opt->attr(selected => "selected") if $selected->{$val};
- my $content = $fclass and $stringify and $fclass->can($stringify) ?
- $fclass->$stringify($_) :
- join(' ', @$_);
+ my $content = ( $fclass && $stringify && $fclass->can($stringify)) ? $fclass->$stringify($item) : join(' ', @$item);
$opt->push_content( $content );
- push @res, $opt;
+ push @res, $opt;
}
- return @res;
+ return @res;
}
#
Maypole::Config->mk_accessors(qw(table_to_class));
-
-
-sub setup_database {
- my ( $self, $config, $namespace, $classes ) = @_;
- $config->{classes} = $classes;
- foreach my $class (@$classes) { $namespace->load_model_subclass($class); }
- $namespace->model_classes_loaded(1);
- $config->{table_to_class} = { map { $_->table => $_ } @$classes };
- $config->{tables} = [ keys %{ $config->{table_to_class} } ];
-}
-
-sub class_of {
- my ( $self, $r, $table ) = @_;
- return $r->config->{table_to_class}->{$table};
-}
-
-
-
-
-1;
-
=head1 NAME
Maypole::Model::CDBI::Plain - Class::DBI model without ::Loader
=head1 METHODS
-=over 4
+=head2 setup
-=item setup_database
+ This method is inherited from Maypole::Model::Base and calls setup_database,
+ which uses Class::DBI::Loader to create and load Class::DBI classes from
+ the given database schema.
-=item class_of
+=head2 setup_database
-=back
+ This method loads the model classes for the application
-See L<Maypole::Model::Base>
+=head1 SEE ALSO
+
+L<Maypole::Model::Base>
+
+L<Maypole::Model::CDBI>
=cut
+
+sub setup_database {
+ my ( $self, $config, $namespace, $classes ) = @_;
+ $config->{classes} = $classes;
+ foreach my $class (@$classes) { $namespace->load_model_subclass($class); }
+ $namespace->model_classes_loaded(1);
+ $config->{table_to_class} = { map { $_->table => $_ } @$classes };
+ $config->{tables} = [ keys %{ $config->{table_to_class} } ];
+}
+
+sub class_of {
+ my ( $self, $r, $table ) = @_;
+ return $r->config->{table_to_class}->{$table};
+}
+
+
+1;
+
+
use Test::More tests=>2;
-
-use_ok("Maypole::HTTPD");
-use_ok("Maypole::HTTPD::Frontend");
+SKIP: {
+ no warnings 'all';
+ my $have_httpd = eval ' use HTTP::Server::Simple::Static; $HTTP::Server::Simple::Static::VERSION; ';
+ warn "have_httpd : $have_httpd\n";
+ skip ('Maypole::HTTPD tests', 2) unless ( $have_httpd );
+ use_ok("Maypole::HTTPD");
+ use_ok("Maypole::HTTPD::Frontend");
+};