| File | /usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers/Trait/Bool.pm |
| Statements Executed | 16 |
| Statement Execution Time | 398µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 958µs | 4.81ms | MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 |
| 1 | 1 | 1 | 311µs | 1.69ms | MooseX::AttributeHelpers::Trait::Bool::BEGIN@3 |
| 1 | 1 | 1 | 7µs | 120µs | MooseX::AttributeHelpers::Trait::Bool::BEGIN@35 |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Bool::__ANON__[:33] |
| 0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Bool::helper_type |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package MooseX::AttributeHelpers::Trait::Bool; | ||||
| 2 | 3 | 99µs | 2 | 6.46ms | # spent 4.81ms (958µs+3.85) within MooseX::AttributeHelpers::Trait::Bool::BEGIN@2 which was called
# once (958µs+3.85ms) by MooseX::AttributeHelpers::BEGIN@13 at line 2 # spent 4.81ms making 1 call to MooseX::AttributeHelpers::Trait::Bool::BEGIN@2
# spent 1.66ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389] |
| 3 | 3 | 210µs | 1 | 1.69ms | # spent 1.69ms (311µs+1.38) within MooseX::AttributeHelpers::Trait::Bool::BEGIN@3 which was called
# once (311µs+1.38ms) by MooseX::AttributeHelpers::BEGIN@13 at line 3 # spent 1.69ms making 1 call to MooseX::AttributeHelpers::Trait::Bool::BEGIN@3 |
| 4 | |||||
| 5 | 1 | 600ns | our $VERSION = '0.23'; | ||
| 6 | 1 | 14µs | $VERSION = eval $VERSION; | ||
| 7 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 8 | |||||
| 9 | 1 | 3µs | 1 | 7.44ms | with 'MooseX::AttributeHelpers::Trait::Base'; # spent 7.44ms making 1 call to Moose::Role::with |
| 10 | |||||
| 11 | sub helper_type { 'Bool' } | ||||
| 12 | |||||
| 13 | # NOTE: | ||||
| 14 | # we don't use the method provider for this | ||||
| 15 | # module since many of the names of the provied | ||||
| 16 | # methods would conflict with keywords | ||||
| 17 | # - SL | ||||
| 18 | |||||
| 19 | 1 | 2µs | 1 | 102µs | has 'method_provider' => ( # spent 102µs making 1 call to Moose::Role::has |
| 20 | is => 'ro', | ||||
| 21 | isa => 'ClassName', | ||||
| 22 | predicate => 'has_method_provider', | ||||
| 23 | default => 'MooseX::AttributeHelpers::MethodProvider::Bool' | ||||
| 24 | ); | ||||
| 25 | |||||
| 26 | before 'process_options_for_provides' => sub { | ||||
| 27 | my ($self, $options, $name) = @_; | ||||
| 28 | |||||
| 29 | # Set some default attribute options here unless already defined | ||||
| 30 | if ((my $type = $self->helper_type) && !exists $options->{isa}){ | ||||
| 31 | $options->{isa} = $type; | ||||
| 32 | } | ||||
| 33 | 1 | 4µs | 1 | 33µs | }; # spent 33µs making 1 call to Moose::Role::before |
| 34 | |||||
| 35 | 3 | 41µs | 2 | 232µs | # spent 120µs (7+112) within MooseX::AttributeHelpers::Trait::Bool::BEGIN@35 which was called
# once (7µs+112µs) by MooseX::AttributeHelpers::BEGIN@13 at line 35 # spent 120µs making 1 call to MooseX::AttributeHelpers::Trait::Bool::BEGIN@35
# spent 112µs making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:478] |
| 36 | |||||
| 37 | 1 | 23µs | 1; | ||
| 38 | |||||
| 39 | =pod | ||||
| 40 | |||||
| 41 | =head1 NAME | ||||
| 42 | |||||
| 43 | MooseX::AttributeHelpers::Bool | ||||
| 44 | |||||
| 45 | =head1 SYNOPSIS | ||||
| 46 | |||||
| 47 | package Room; | ||||
| 48 | use Moose; | ||||
| 49 | use MooseX::AttributeHelpers; | ||||
| 50 | |||||
| 51 | has 'is_lit' => ( | ||||
| 52 | metaclass => 'Bool', | ||||
| 53 | is => 'rw', | ||||
| 54 | isa => 'Bool', | ||||
| 55 | default => sub { 0 }, | ||||
| 56 | provides => { | ||||
| 57 | set => 'illuminate', | ||||
| 58 | unset => 'darken', | ||||
| 59 | toggle => 'flip_switch', | ||||
| 60 | not => 'is_dark' | ||||
| 61 | } | ||||
| 62 | ); | ||||
| 63 | |||||
| 64 | my $room = Room->new(); | ||||
| 65 | $room->illuminate; # same as $room->is_lit(1); | ||||
| 66 | $room->darken; # same as $room->is_lit(0); | ||||
| 67 | $room->flip_switch; # same as $room->is_lit(not $room->is_lit); | ||||
| 68 | return $room->is_dark; # same as !$room->is_lit | ||||
| 69 | |||||
| 70 | =head1 DESCRIPTION | ||||
| 71 | |||||
| 72 | This provides a simple boolean attribute, which supports most of the | ||||
| 73 | basic math operations. | ||||
| 74 | |||||
| 75 | =head1 METHODS | ||||
| 76 | |||||
| 77 | =over 4 | ||||
| 78 | |||||
| 79 | =item B<meta> | ||||
| 80 | |||||
| 81 | =item B<helper_type> | ||||
| 82 | |||||
| 83 | =item B<method_constructors> | ||||
| 84 | |||||
| 85 | =item B<has_method_provider> | ||||
| 86 | |||||
| 87 | =item B<method_provider> | ||||
| 88 | |||||
| 89 | =back | ||||
| 90 | |||||
| 91 | =head1 PROVIDED METHODS | ||||
| 92 | |||||
| 93 | It is important to note that all those methods do in place | ||||
| 94 | modification of the value stored in the attribute. | ||||
| 95 | |||||
| 96 | =over 4 | ||||
| 97 | |||||
| 98 | =item I<set> | ||||
| 99 | |||||
| 100 | Sets the value to C<1>. | ||||
| 101 | |||||
| 102 | =item I<unset> | ||||
| 103 | |||||
| 104 | Set the value to C<0>. | ||||
| 105 | |||||
| 106 | =item I<toggle> | ||||
| 107 | |||||
| 108 | Toggle the value. If it's true, set to false, and vice versa. | ||||
| 109 | |||||
| 110 | =item I<not> | ||||
| 111 | |||||
| 112 | Equivalent of 'not C<$value>'. | ||||
| 113 | |||||
| 114 | =back | ||||
| 115 | |||||
| 116 | =head1 BUGS | ||||
| 117 | |||||
| 118 | All complex software has bugs lurking in it, and this module is no | ||||
| 119 | exception. If you find a bug please either email me, or add the bug | ||||
| 120 | to cpan-RT. | ||||
| 121 | |||||
| 122 | =head1 AUTHOR | ||||
| 123 | |||||
| 124 | Jason May | ||||
| 125 | |||||
| 126 | =head1 COPYRIGHT AND LICENSE | ||||
| 127 | |||||
| 128 | Copyright 2007-2009 by Infinity Interactive, Inc. | ||||
| 129 | |||||
| 130 | L<http://www.iinteractive.com> | ||||
| 131 | |||||
| 132 | This library is free software; you can redistribute it and/or modify | ||||
| 133 | it under the same terms as Perl itself. | ||||
| 134 | |||||
| 135 | =cut |