<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Moose::Meta::Attribute::Native::Trait::Counter;
our $VERSION = '2.2011';

use Moose::Role;
with 'Moose::Meta::Attribute::Native::Trait';

sub _helper_type { 'Num' }
sub _root_types { 'Num', 'Int' }

no Moose::Role;

1;

# ABSTRACT: Helper trait for Int attributes which represent counters

__END__

=pod

=encoding UTF-8

=head1 NAME

Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for Int attributes which represent counters

=head1 VERSION

version 2.2011

=head1 SYNOPSIS

  package MyHomePage;
  use Moose;

  has 'counter' =&gt; (
      traits  =&gt; ['Counter'],
      is      =&gt; 'ro',
      isa     =&gt; 'Num',
      default =&gt; 0,
      handles =&gt; {
          inc_counter   =&gt; 'inc',
          dec_counter   =&gt; 'dec',
          reset_counter =&gt; 'reset',
      },
  );

  my $page = MyHomePage-&gt;new();
  $page-&gt;inc_counter;    # same as $page-&gt;counter( $page-&gt;counter + 1 );
  $page-&gt;dec_counter;    # same as $page-&gt;counter( $page-&gt;counter - 1 );

  my $count_by_twos = 2;
  $page-&gt;inc_counter($count_by_twos);

=head1 DESCRIPTION

This trait provides native delegation methods for counters. A counter can be
any sort of number (integer or not). The delegation methods allow you to
increment, decrement, or reset the value.

=head1 DEFAULT TYPE

If you don't provide an C&lt;isa&gt; value for your attribute, it will default to
C&lt;Num&gt;.

=head1 PROVIDED METHODS

=over 4

=item * B&lt;set($value)&gt;

Sets the counter to the specified value and returns the new value.

This method requires a single argument.

=item * B&lt;inc&gt;

=item * B&lt;inc($arg)&gt;

Increases the attribute value by the amount of the argument, or by 1 if no
argument is given. This method returns the new value.

This method accepts a single argument.

=item * B&lt;dec&gt;

=item * B&lt;dec($arg)&gt;

Decreases the attribute value by the amount of the argument, or by 1 if no
argument is given. This method returns the new value.

This method accepts a single argument.

=item * B&lt;reset&gt;

Resets the value stored in this slot to its default value, and returns the new
value.

=back

=head1 BUGS

See L&lt;Moose/BUGS&gt; for details on reporting bugs.

=head1 AUTHORS

=over 4

=item *

Stevan Little &lt;stevan.little@iinteractive.com&gt;

=item *

Dave Rolsky &lt;autarch@urth.org&gt;

=item *

Jesse Luehrs &lt;doy@tozt.net&gt;

=item *

Shawn M Moore &lt;code@sartak.org&gt;

=item *

×™×•×‘×œ ×§×•×’'×ž×Ÿ (Yuval Kogman) &lt;nothingmuch@woobling.org&gt;

=item *

Karen Etheridge &lt;ether@cpan.org&gt;

=item *

Florian Ragwitz &lt;rafl@debian.org&gt;

=item *

Hans Dieter Pearcey &lt;hdp@weftsoar.net&gt;

=item *

Chris Prather &lt;chris@prather.org&gt;

=item *

Matt S Trout &lt;mst@shadowcat.co.uk&gt;

=back

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2006 by Infinity Interactive, Inc.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
</pre></body></html>