DBIx-Frame
view release on metacpan or search on metacpan
DBIx/Frame.pm view on Meta::CPAN
$LIST = [
{ 'Room' => '$$RoomNumber$$ $$Building$$' },
{ 'Port Speed' => '$$PortSpeed$$' } ,
'BoxNumber', 'PortNumber', 'PortMachine' ];
Another example (from TCB::Travel::Event):
$LIST = [
'Title', 'Location',
{ 'Dates' => [ \&dates, '$$Start$$', '$$End$$' ] },
{ 'URL' => [ \&url, '$$URL$$' ] }
];
Related functions: C<list()>, C<listref()>, C<list_head()>, C<make_list()>
=item HTML
This is a code reference that, when invoked, will return a string
containing a table with form entries to allow the creation of new entries
and the updates of old ones. This isn't necessary, but is probably worth
your time to create.
The function should take inputs like this:
$self - a reference to the DBIx::Frame object
$entry - a hash reference containing the default data, with the keys
being the table fields and the values being their contents.
$type - the type of function you're working with, typically one of
'create', 'search', 'edit', or 'view'.
$opts - a hash reference containing extra flags that are passed on from
the script (not the user!) to the subroutine. These are used
to customize the output of html() based on the invoking script.
Note that this is not documented in the below example!
@rest - anything else it feels like taking
The returned HTML can either be a table (which doesn't require any
stylesheet information) or properly formatted HTML4. If the latter, you
may want to make sure scripts that invoke this function also use a
relevant stylesheet.
Example (from TCB::Publications::Files):
sub html {
my ($self, $entry, $type, $options, @rest) = @_;
my $cgi = new CGI; $entry ||= {};
my %public = ( 0 => "Public", 1 => "Internal Only" );
if (lc $type eq 'search') { $public{''} = "*" }
my @types = sort @LINKTYPES; unshift @types, '';
my @codes = sort grep { $_ if /\S+/ }
$self->select_fieldlist('Papers', 'TBCode');
unshift @codes, '';
my @return = <<HTML;
<div class="basetable">
<div class="row2">
<span class="label">TBCode</span>
<span class="formw">
@{[ $cgi->popup_menu('TBCode', \@codes, $$entry{TBCode} || "") ]}
</span>
<span class="label">File Type</span>
<span class="formw">
@{[ $cgi->popup_menu('Type', \@types, $$entry{Type} || "") ]}
</span>
</div>
<div class="row1">
<span class="label">Location</span>
<span class="formw">
@{[ $cgi->textfield('Location', $$entry{Location} || "", 70, 1024) ]}
</span>
</div>
<div class="row1">
<span class="label">Description</span>
<span class="formw">
@{[ $cgi->textarea(-name=>'Description',
-default=>$$entry{Description} || "",
-rows=>7, -cols=>60, -maxlength=>65535,
-wrap=>'physical') ]}
</span>
</div>
<div class="row1">
<span class="label">Restricted?</span>
<span class="formw">
@{[ $cgi->popup_menu('Restricted', [sort keys %public],
$$entry{Restricted} || "", \%public) ]}
</span>
</div>
<div class="submitbar"> @{[ $cgi->submit(-name=>"Submit") ]} </div>
</div>
HTML
wantarray ? @return : join("\n", @return);
}
Related functions: C<html()>, C<htmlref()>
=item TEXT
This is a code reference that, when invoked, will return a string
containing the data that you wish to display in text. This mostly
pertains to C<DBIx::Frame::Text>.
Example (from TCB::mysql::user):
sub text {
my ($self, $entry) = @_;
return sprintf(
"%22s %22s %22s %1s%1s%1s%1s%1s%1s%1s%1s%1s%1s",
$$entry{Host}, $$entry{User}, $$entry{Password},
$$entry{Select_priv}, $$entry{Insert_priv},
$$entry{Delete_priv}, $$entry{Create_priv},
$$entry{Drop_priv}, $$entry{Grant_priv},
$$entry{References_priv}, $$entry{Index_priv},
$$entry{Alter_priv} );
}
Related functions: C<text()>, C<textref()>
=back
=head1 NOTES
This module was designed for use with MySQL, and hasn't been tested with
anything else. Most things should be portable, however, probably with
little effort; only some internal code may need changing.
=head1 REQUIREMENTS
Perl 5 or better, the DBI module, and the appropriate drivers for your
database (DBD::mysql, in our case). To really make it useful you'll want
a set of DBIx::Frame database modules, such as C<TCB::AddressBook> or
C<TCB::Publications>, though you can (and should) design your own.
=head1 SEE ALSO
B<DBI>, B<DBIx::Frame::CGI>. Many of the databases on the MDTools web
site (B<http://www.ks.uiuc.edu/Development/MDTools/>) offer further
examples of how to design databases and use this package.
=head1 TODO
( run in 1.076 second using v1.01-cache-2.11-cpan-364913b4093 )