| File | /usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers/Trait/Number.pm |
| Statements Executed | 12 |
| Statement Execution Time | 513µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 17µs | 1.83ms | MooseX::AttributeHelpers::Trait::Number::BEGIN@2 |
| 1 | 1 | 1 | 9µs | 120µs | MooseX::AttributeHelpers::Trait::Number::BEGIN@56 |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:26] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:27] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:30] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:31] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:34] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:35] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:38] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:39] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:42] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:43] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:46] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:47] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:50] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:51] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::__ANON__[:53] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Number::helper_type |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package MooseX::AttributeHelpers::Trait::Number; | ||||
| 2 | 3 | 409µs | 2 | 3.64ms | # spent 1.83ms (17µs+1.81) within MooseX::AttributeHelpers::Trait::Number::BEGIN@2 which was called
# once (17µs+1.81ms) by MooseX::AttributeHelpers::BEGIN@15 at line 2 # spent 1.83ms making 1 call to MooseX::AttributeHelpers::Trait::Number::BEGIN@2
# spent 1.81ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389] |
| 3 | |||||
| 4 | 1 | 700ns | our $VERSION = '0.23'; | ||
| 5 | 1 | 17µs | $VERSION = eval $VERSION; | ||
| 6 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 7 | |||||
| 8 | 1 | 3µs | 1 | 2.40ms | with 'MooseX::AttributeHelpers::Trait::Base'; # spent 2.40ms making 1 call to Moose::Role::with |
| 9 | |||||
| 10 | sub helper_type { 'Num' } | ||||
| 11 | |||||
| 12 | # NOTE: | ||||
| 13 | # we don't use the method provider for this | ||||
| 14 | # module since many of the names of the provied | ||||
| 15 | # methods would conflict with keywords | ||||
| 16 | # - SL | ||||
| 17 | |||||
| 18 | has 'method_constructors' => ( | ||||
| 19 | is => 'ro', | ||||
| 20 | isa => 'HashRef', | ||||
| 21 | lazy => 1, | ||||
| 22 | default => sub { | ||||
| 23 | return +{ | ||||
| 24 | set => sub { | ||||
| 25 | my ($attr, $reader, $writer) = @_; | ||||
| 26 | return sub { $writer->($_[0], $_[1]) }; | ||||
| 27 | }, | ||||
| 28 | add => sub { | ||||
| 29 | my ($attr, $reader, $writer) = @_; | ||||
| 30 | return sub { $writer->($_[0], $reader->($_[0]) + $_[1]) }; | ||||
| 31 | }, | ||||
| 32 | sub => sub { | ||||
| 33 | my ($attr, $reader, $writer) = @_; | ||||
| 34 | return sub { $writer->($_[0], $reader->($_[0]) - $_[1]) }; | ||||
| 35 | }, | ||||
| 36 | mul => sub { | ||||
| 37 | my ($attr, $reader, $writer) = @_; | ||||
| 38 | return sub { $writer->($_[0], $reader->($_[0]) * $_[1]) }; | ||||
| 39 | }, | ||||
| 40 | div => sub { | ||||
| 41 | my ($attr, $reader, $writer) = @_; | ||||
| 42 | return sub { $writer->($_[0], $reader->($_[0]) / $_[1]) }; | ||||
| 43 | }, | ||||
| 44 | mod => sub { | ||||
| 45 | my ($attr, $reader, $writer) = @_; | ||||
| 46 | return sub { $writer->($_[0], $reader->($_[0]) % $_[1]) }; | ||||
| 47 | }, | ||||
| 48 | abs => sub { | ||||
| 49 | my ($attr, $reader, $writer) = @_; | ||||
| 50 | return sub { $writer->($_[0], abs($reader->($_[0])) ) }; | ||||
| 51 | }, | ||||
| 52 | } | ||||
| 53 | } | ||||
| 54 | 1 | 4µs | 1 | 128µs | ); # spent 128µs making 1 call to Moose::Role::has |
| 55 | |||||
| 56 | 3 | 58µs | 2 | 231µs | # spent 120µs (9+111) within MooseX::AttributeHelpers::Trait::Number::BEGIN@56 which was called
# once (9µs+111µs) by MooseX::AttributeHelpers::BEGIN@15 at line 56 # spent 120µs making 1 call to MooseX::AttributeHelpers::Trait::Number::BEGIN@56
# spent 111µs making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:478] |
| 57 | |||||
| 58 | 1 | 22µs | 1; | ||
| 59 | |||||
| 60 | =pod | ||||
| 61 | |||||
| 62 | =head1 NAME | ||||
| 63 | |||||
| 64 | MooseX::AttributeHelpers::Number | ||||
| 65 | |||||
| 66 | =head1 SYNOPSIS | ||||
| 67 | |||||
| 68 | package Real; | ||||
| 69 | use Moose; | ||||
| 70 | use MooseX::AttributeHelpers; | ||||
| 71 | |||||
| 72 | has 'integer' => ( | ||||
| 73 | metaclass => 'Number', | ||||
| 74 | is => 'ro', | ||||
| 75 | isa => 'Int', | ||||
| 76 | default => sub { 5 }, | ||||
| 77 | provides => { | ||||
| 78 | set => 'set', | ||||
| 79 | add => 'add', | ||||
| 80 | sub => 'sub', | ||||
| 81 | mul => 'mul', | ||||
| 82 | div => 'div', | ||||
| 83 | mod => 'mod', | ||||
| 84 | abs => 'abs', | ||||
| 85 | } | ||||
| 86 | ); | ||||
| 87 | |||||
| 88 | my $real = Real->new(); | ||||
| 89 | $real->add(5); # same as $real->integer($real->integer + 5); | ||||
| 90 | $real->sub(2); # same as $real->integer($real->integer - 2); | ||||
| 91 | |||||
| 92 | =head1 DESCRIPTION | ||||
| 93 | |||||
| 94 | This provides a simple numeric attribute, which supports most of the | ||||
| 95 | basic math operations. | ||||
| 96 | |||||
| 97 | =head1 METHODS | ||||
| 98 | |||||
| 99 | =over 4 | ||||
| 100 | |||||
| 101 | =item B<meta> | ||||
| 102 | |||||
| 103 | =item B<helper_type> | ||||
| 104 | |||||
| 105 | =item B<method_constructors> | ||||
| 106 | |||||
| 107 | =back | ||||
| 108 | |||||
| 109 | =head1 PROVIDED METHODS | ||||
| 110 | |||||
| 111 | It is important to note that all those methods do in place | ||||
| 112 | modification of the value stored in the attribute. | ||||
| 113 | |||||
| 114 | =over 4 | ||||
| 115 | |||||
| 116 | =item I<set ($value)> | ||||
| 117 | |||||
| 118 | Alternate way to set the value. | ||||
| 119 | |||||
| 120 | =item I<add ($value)> | ||||
| 121 | |||||
| 122 | Adds the current value of the attribute to C<$value>. | ||||
| 123 | |||||
| 124 | =item I<sub ($value)> | ||||
| 125 | |||||
| 126 | Subtracts the current value of the attribute to C<$value>. | ||||
| 127 | |||||
| 128 | =item I<mul ($value)> | ||||
| 129 | |||||
| 130 | Multiplies the current value of the attribute to C<$value>. | ||||
| 131 | |||||
| 132 | =item I<div ($value)> | ||||
| 133 | |||||
| 134 | Divides the current value of the attribute to C<$value>. | ||||
| 135 | |||||
| 136 | =item I<mod ($value)> | ||||
| 137 | |||||
| 138 | Modulus the current value of the attribute to C<$value>. | ||||
| 139 | |||||
| 140 | =item I<abs> | ||||
| 141 | |||||
| 142 | Sets the current value of the attribute to its absolute value. | ||||
| 143 | |||||
| 144 | =back | ||||
| 145 | |||||
| 146 | =head1 BUGS | ||||
| 147 | |||||
| 148 | All complex software has bugs lurking in it, and this module is no | ||||
| 149 | exception. If you find a bug please either email me, or add the bug | ||||
| 150 | to cpan-RT. | ||||
| 151 | |||||
| 152 | =head1 AUTHOR | ||||
| 153 | |||||
| 154 | Robert Boone | ||||
| 155 | |||||
| 156 | =head1 COPYRIGHT AND LICENSE | ||||
| 157 | |||||
| 158 | Copyright 2007-2009 by Infinity Interactive, Inc. | ||||
| 159 | |||||
| 160 | L<http://www.iinteractive.com> | ||||
| 161 | |||||
| 162 | This library is free software; you can redistribute it and/or modify | ||||
| 163 | it under the same terms as Perl itself. | ||||
| 164 | |||||
| 165 | =cut |