Catalyst-View-EmbeddedPerl-PerRequest

 view release on metacpan or  search on metacpan

lib/Catalyst/View/EmbeddedPerl/PerRequest.pm  view on Meta::CPAN


  <a href="<%= attr('href', $url) %>">Link</a>

=head2 style

  style($style)

Returns a C<style> attribute string.  Example usage:

  <div <%= style('color: red;') %>>Content</div>

=head2 class

  class($class)

Returns a C<class> attribute string.  Example usage:

  <div <%= class('important') %>>Content</div>

=head2 checked 
  
    checked($checked)

Returns a C<checked> attribute string.  Example usage:
  
    <input type="checkbox" <%= checked($checked) %> />

=head2 selected

    selected($selected)

Returns a C<selected> attribute string.  Example usage:

    <select>
      <option value="1" <%= selected($selected) %>>One</option>
      <option value="2" <%= selected($selected) %>>Two</option>
    </select>

=head2 disabled

    disabled($disabled)

Returns a C<disabled> attribute string.  Example usage:

    <input type="text" <%= disabled($disabled) %> />

=head2 readonly

    readonly($readonly)

Returns a C<readonly> attribute string.  Example usage:

    <input type="text" <%= readonly($readonly) %> />

=head2 required

    required($required)

Returns a C<required> attribute string.  Example usage:

    <input type="text" <%= required($required) %> />

=head2 href

    href(@href_parts)

Returns an C<href> attribute string.  Example usage:


    <a <%= href('/path/to/page') %>>Link</a>

=head2 src
  
      src(@src_parts)

Returns a C<src> attribute string.  Example usage:

    <img <%= src('/path/to/image.jpg') %> />

=head2 data

    data($data)

Returns a C<data> attribute string.  Example usage: 
  
      <div <%= data({'id', '123'}) %>>Content</div> 

=head2 over

  my $result = $self->over($iterable, sub {
      my ($item, $info) = @_;
      return "<p>Item: $item, Index: " . $info->current . "</p>";
  });

In a template:

  <%= over($iterable, sub($item, $info) {
      <p>Item: <%= $item %>, Index: <%= $info->current %></p>
  }) %>

(Remember in the template calling helpers via C<$self> is your option)

Executes a callback for each item in an iterable, providing metadata about the iteration 
through a L<Catalyst::View::EmbeddedPerl::PerRequest::EachInfo> object.

Although you can use standard Perl looping constructs in your templates, the C<over>
helper provides the addional metadata about the iteration that can be useful in some
situations related to display logic, such as changing the CSS based on even/odd rows
or tracking the item number.

=head3 Arguments

=over

=item * C<$iterable> - An iterable source. This can be:

=over

=item * An array reference (e.g., C<[1, 2, 3]>).

=item * A coderef that returns the next value when called (e.g., C<sub { ... }>).



( run in 0.588 second using v1.01-cache-2.11-cpan-e1769b4cff6 )