ASP4x-Linker
view release on metacpan or search on metacpan
lib/ASP4x/Linker.pm view on Meta::CPAN
# If the page size is changed, go back to page 1:
$linker->widget("widgetA")->on_change( page_size => sub {
my ($s) = @_;
$s->set( page_number => 1 );
});
# Add another widget:
$linker->add_widget(
name => "widgetB",
attrs => [qw( keywords tag start_date stop_date )]
);
# Chained accessor goodness:
# New as of v1.001
my $fancy_uri = $linker->widget('widgetA')->set( %args )->uri;
=head2 Setting Variables
Since the C<$linker> starts out with only the variables found in C<$ENV{REQUEST_URI}>
or in the C<base_href> argument, calling C<< $linker->uri() >> on a new linker object
will return the same uri that you are currently on (eg: C</some-page.asp>
To generate links that contain specific attributes, set the attributes for those
widgets and then call C<< $linker->uri() >> to get the resultant uri to match.
$linker->widget("widgetA")->set( page_number => 2 );
$uri = $linker->uri;
# $uri is now "/some-page.asp?widgetA.page_number=2"
lib/ASP4x/Linker.pm view on Meta::CPAN
B<Option 2>: Use ASP4x::Linker. Register 2 "widgets" (albums and genres) and let the linker know that they both have C<page_number>, C<page_size>, C<sort_col> and C<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.
=back
=head1 CONSTRUCTOR
=head2 new( [ base_href => $ENV{REQUEST_URI} ] )
Returns a new C<ASP4x::Linker> object using the supplied C<base_href> value as the "starting point"
for all links that will be generated.
If no C<base_href> is provided, the value of C<$ENV{REQUEST_URI}> will be used instead.
=head1 PUBLIC READ-ONLY PROPERTIES
=head2 base_href
Returns the C<base_href> value in use for the linker object.
( run in 0.589 second using v1.01-cache-2.11-cpan-0d8aa00de5b )