NAME
ASP4x::Linker - In-page persistence of widget-specific variables.
SYNOPSIS
(Within /some-page.asp)
use ASP4x::Linker;
my $linker = ASP4x::Linker->new();
$linker->add_widget(
name => "albums",
attrs => [qw/ page_number page_size sort_field sort_dir /]
);
$linker->add_widget(
name => "genres",
attrs => [qw/ page_number page_size sort_field sort_dir /]
);
$linker->add_widget(
name => "artists",
attrs => [qw/ page_number page_size sort_field sort_dir /]
);
...later, on the same page...
For more info click <a href="<%= $linker->uri() %>">Here</a>.
Then:
$linker->widget('albums')->page_number(4);
<a href="<%= $linker->uri() %>">Page 4</a> # /some-page.asp?albums.page_number=4
$linker->reset();
Or
my $url = $linker->uri({
albums => { page_number => 4 }
});
# /some-page.asp?albums.page_number=4
Or
my $url = $linker->uri({
albums => { page_number => 4 },
genres => {
page_number => 1,
page_size => 20,
sort_col => 'name',
sort_dir => 'desc'
}
});
# /some-page.asp?albums.page_number=4&genres.page_number=1&genres.page_size=20&genres.sort_col=name&genres.sort_dir=desc
DESCRIPTION
ASP4x::Linker
aims to solve the age-old problem of:
How do I change one widget on the page without losing my settings for all the other widgets on the page?
OK - say you have one data grid on your web page that allows paging and sorting. You can move forward and backward between pages, change the sorting - life's great. THEN your boss says:
We need to have two of those on the same page. One for Albums and one for Genres.
Now you have 2 options.
Option 1: If a user pages "Albums" to page 4, then pages "Genres" to page 2, you forget that "Albums" was on page 4.
Option 2: Use ASP4x::Linker. Register 2 "widgets" (albums and genres) and let the linker know that they both have page_number
, page_size
, sort_col
and sort_dir
attributes. When the user makes paging or sorting changes in Albums, the stuff for Genres will persist between requests without any extra effort.
CONSTRUCTOR
new( [ base_href => $ENV{REQUEST_URI} ] )
PUBLIC READ-ONLY PROPERTIES
base_href
Returns the base_href
value in use for the linker object.
widgets
Returns an array of ASP4x::Widget objects assigned to the linker.
PUBLIC METHODS
add_widget( name => $str, attrs => \@attrNames )
Adds a "widget" to
widget( $name )
Returns an individual ASP4x::Linker::Widget object by that name.
Returns undef if no widget by that name is found.
uri( [$properties] )
Returns the uri for all widgets based on the intersect of:
The incoming form data from the original request
Individually-set values for each widget in the collection.
Any properties provided as an argument to
uri()
.
reset( )
Resets all widgets to their original values from the original request.
SEE ALSO
ASP4, ASP4x::Router, Router::Generic
AUTHOR
John Drago <jdrago_999@yahoo.com>
LICENSE
This software is Free software and may be used and redistributed under the same terms as Perl itself.