| 1 | package Graphics::Primitive::Oriented; | ||
| 2 | use Moose::Role; | ||
| 3 | |||
| 4 | use Moose::Util::TypeConstraints; | ||
| 5 | |||
| 6 | enum 'Graphics::Primitive::Orientations' => [qw(vertical horizontal)]; | ||
| 7 | |||
| 8 | has 'orientation' => ( | ||
| 9 | is => 'rw', | ||
| 10 | isa => 'Graphics::Primitive::Orientations', | ||
| 11 | ); | ||
| 12 | |||
| 13 | sub is_vertical { | ||
| 14 | my ($self) = @_; | ||
| 15 | |||
| 16 | return 0 unless $self->orientation; | ||
| 17 | |||
| 18 | return ($self->orientation eq 'vertical'); | ||
| 19 | } | ||
| 20 | |||
| 21 | sub is_horizontal { | ||
| 22 | my ($self) = @_; | ||
| 23 | |||
| 24 | !$self->is_vertical; | ||
| 25 | } | ||
| 26 | |||
| 27 | no Moose; | ||
| 28 | 1; | ||
| 29 | __END__ | ||
| 30 | =head1 NAME | ||
| 31 | |||
| 32 | Graphics::Primitive::Oriented - Role for components that care about | ||
| 33 | orientation. | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | Some components (or things that use components) require a bit more information | ||
| 38 | than origin and width/height. The orientation role allows a component to | ||
| 39 | specify whether is vertically or horizontally oriented. | ||
| 40 | |||
| 41 | package My::Component; | ||
| 42 | |||
| 43 | extends 'Graphics::Primitive::Component'; | ||
| 44 | |||
| 45 | with 'Graphics::Primitive::Oriented'; | ||
| 46 | |||
| 47 | 1; | ||
| 48 | |||
| 49 | =head1 METHODS | ||
| 50 | |||
| 51 | =over | ||
| 52 | |||
| 53 | =item I<is_vertical> | ||
| 54 | |||
| 55 | Returns true if the component is vertically oriented. | ||
| 56 | |||
| 57 | =item I<is_horizontal> | ||
| 58 | |||
| 59 | Returns true if the component is not vertically oriented. | ||
| 60 | |||
| 61 | =item I<orientation> | ||
| 62 | |||
| 63 | The way a component is oriented. Values allowed are 'horizontal' or | ||
| 64 | 'vertical'. | ||
| 65 | |||
| 66 | |||
| 67 | =back | ||
| 68 | |||
| 69 | =head1 AUTHOR | ||
| 70 | |||
| 71 | Cory Watson, C<< <gphat@cpan.org> >> | ||
| 72 | |||
| 73 | =head1 SEE ALSO | ||
| 74 | |||
| 75 | perl(1) | ||
| 76 | |||
| 77 | =head1 COPYRIGHT & LICENSE | ||
| 78 | |||
| 79 | Copyright 2008-2010 by Cory G Watson. | ||
| 80 | |||
| 81 | This program is free software; you can redistribute it and/or modify it | ||
| 82 | under the same terms as Perl itself. |