The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

ASP4x::Linker::Widget - A single item that should be persisted via links.

SYNOPSIS

  use ASP4x::Linker;
  
  my $linker = ASP4x::Linker->new();
  
  # Add a widget:
  $linker->add_widget(
    name  => 'albums',
    attrs => [qw( page_number page_size sort_col sort_dir )]
  );
  
  # Get the widget:
  my $widget = $linker->widget('albums');
  
  # Change some attributes:
  $widget->set( page_size   => 10 );
  $widget->set( page_number => 4 );
  
  # Get the value of some attributes:
  $widget->get( 'page_size' );    # 10
  $widget->get( 'page_number' );  # 4

  # Make page_number reset to 1 if the page_size is changed:
  $widget->on_change( page_size => sub {
    my $s = shift;
    $s->set( page_number => 1 );
  });
  
  $widget->set( page_size => 20 );
  print $widget->get( 'page_number' );  # 1
  
  # Set multiple values at once:
  $widget->set( %args );
  
  # Set multiple values at once and get the uri:
  warn $widget->set( %args )->uri();
  
  # Set multiple values by chaining and get the uri:
  warn $widget->set( foo => 'bar' )->set( baz => 'bux' )->uri();

DESCRIPTION

ASP4x::Linker::Widget provides a simple, simple interface to a "thing" on your web page (which we'll call a "widget").

A "widget" can be anything. My experience generally means that a widget is a data grid that supports paging and sorting through multiple records. However a widget could represent anything you want it to, as long as you can describe it with a name and and arrayref of attrs (attributes). The attrs arrayref for a data grid might look like what you see in the example above:

  attrs => [qw( page_number page_size sort_col sort_dir )]

In English, a "widget" can be anything. The word "widget" could be replaced with "thing" - so in this case a "widget" is just a "thing" - anything (with a name and attributes).

PUBLIC PROPERTIES

vars

Returns a hashref of all name/value pairs of attributes and their current values.

attrs

Returns an array of the names of the widget's attributes.

PUBLIC METHODS

reset( )

Restores the widget's vars to its original state - as it was when the widget was first instantiated.

set( $attr => $value )

Changes the value of an attribute to a new value.

NOTE: As of version , attempts to apply a value to a non-existant attribute will result in a runtime exception.

get( $attr )

Returns the current value of the attribute.

on_change( $attr => sub { ... } )

Adds a trigger to the widget that will be called when the given attribute's value is changed via set().

uri()

Just a wrapper around the widget's parent ASP4x::Linker object.

SEE ALSO

ASP4x::Linker

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.