| 1 | package Table::Simple::Column; | ||||||||||
| 2 | |||||||||||
| 3 | 7 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 7 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 7 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | Table::Simple::Column - A collection of data points organized into rows | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | Typically you want to use this module in conjunction with L<Table::Simple> | ||||||||||
| 14 | table object. | ||||||||||
| 15 | |||||||||||
| 16 | =head2 ATTRIBUTES | ||||||||||
| 17 | |||||||||||
| 18 | =over 4 | ||||||||||
| 19 | |||||||||||
| 20 | =item width | ||||||||||
| 21 | |||||||||||
| 22 | This attribute stores the length of the widest element in the column including | ||||||||||
| 23 | the name of the column. | ||||||||||
| 24 | |||||||||||
| 25 | =back | ||||||||||
| 26 | |||||||||||
| 27 | =cut | ||||||||||
| 28 | |||||||||||
| 29 | 7 | has 'width' => ( | |||||||||
| 30 | is => 'rw', | ||||||||||
| 31 | isa => 'Int', | ||||||||||
| 32 | lazy_build => 1, | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | =over 4 | ||||||||||
| 36 | |||||||||||
| 37 | =item name | ||||||||||
| 38 | |||||||||||
| 39 | This is a required attribute which stores the name of the column. It should | ||||||||||
| 40 | match the name of an attribute on a class to be scanned by the software. | ||||||||||
| 41 | |||||||||||
| 42 | =back | ||||||||||
| 43 | |||||||||||
| 44 | =cut | ||||||||||
| 45 | |||||||||||
| 46 | 7 | has 'name' => ( | |||||||||
| 47 | is => 'ro', | ||||||||||
| 48 | isa => 'Str', | ||||||||||
| 49 | required => 1, | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | =over 4 | ||||||||||
| 53 | |||||||||||
| 54 | =item output_format | ||||||||||
| 55 | |||||||||||
| 56 | This attribute controls the output layout. This should match a method in | ||||||||||
| 57 | L<Table::Simple::Output> or a subclass of that. The following methods | ||||||||||
| 58 | are available in the standard L<Table::Simple::Output> class: | ||||||||||
| 59 | |||||||||||
| 60 | =over 4 | ||||||||||
| 61 | |||||||||||
| 62 | =item left_justify | ||||||||||
| 63 | |||||||||||
| 64 | =item center | ||||||||||
| 65 | |||||||||||
| 66 | =item right_justify | ||||||||||
| 67 | |||||||||||
| 68 | =back | ||||||||||
| 69 | |||||||||||
| 70 | =back | ||||||||||
| 71 | |||||||||||
| 72 | =cut | ||||||||||
| 73 | |||||||||||
| 74 | 7 | has 'output_format' => ( | |||||||||
| 75 | is => 'rw', | ||||||||||
| 76 | isa => 'Str', | ||||||||||
| 77 | default => 'left_justify', | ||||||||||
| 78 | ); | ||||||||||
| 79 | |||||||||||
| 80 | =over 4 | ||||||||||
| 81 | |||||||||||
| 82 | =item rows | ||||||||||
| 83 | |||||||||||
| 84 | This attribute is a collection of data elements corresponding to the | ||||||||||
| 85 | attribute values matching the column name. | ||||||||||
| 86 | |||||||||||
| 87 | This attribute has a number of methods which permit you to manipulate | ||||||||||
| 88 | the collection. | ||||||||||
| 89 | |||||||||||
| 90 | =back | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | has 'rows' => ( | ||||||||||
| 95 | is => 'ro', | ||||||||||
| 96 | isa => 'ArrayRef[Str]', | ||||||||||
| 97 | traits => [ 'Array' ], | ||||||||||
| 98 | 8 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 99 | 7 | handles => { | |||||||||
| 100 | 'add_row' => 'push', | ||||||||||
| 101 | 'get_rows' => 'elements', | ||||||||||
| 102 | 'get_row' => 'get', | ||||||||||
| 103 | }, | ||||||||||
| 104 | lazy => 1, | ||||||||||
| 105 | ); | ||||||||||
| 106 | |||||||||||
| 107 | 16 | ▶ | after 'add_row' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 108 | 16 | my $self = shift; | |||||||||
| 109 | 16 | my $new = shift; | |||||||||
| 110 | |||||||||||
| 111 | 16 | ▶ | if ( length($new) > $self->width ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | 4 | $self->width( length($new) ); | |||||||||
| 113 | } | ||||||||||
| 114 | 7 | }; | |||||||||
| 115 | |||||||||||
| 116 | =head2 METHODS | ||||||||||
| 117 | |||||||||||
| 118 | =over 4 | ||||||||||
| 119 | |||||||||||
| 120 | =item add_row( $string ) | ||||||||||
| 121 | |||||||||||
| 122 | This method adds a new row value (string scalar) to the collection. | ||||||||||
| 123 | |||||||||||
| 124 | =item get_rows | ||||||||||
| 125 | |||||||||||
| 126 | This method returns all values stored in the collection. It preserves the | ||||||||||
| 127 | order in which values were added to the collection. | ||||||||||
| 128 | |||||||||||
| 129 | =item get_row | ||||||||||
| 130 | |||||||||||
| 131 | This method returns a specific value stored in collection. It takes the | ||||||||||
| 132 | desired value's index as input and returns the value as output. | ||||||||||
| 133 | |||||||||||
| 134 | =back | ||||||||||
| 135 | |||||||||||
| 136 | =cut | ||||||||||
| 137 | |||||||||||
| 138 | 8 | ▶ | sub _build_width { | ||||||||
|
Subroutine
_build_width: called CC=2 SCAR=7.2
| |||||||||||
| 139 | 8 | my $self = shift; | |||||||||
| 140 | |||||||||||
| 141 | 8 | ▶ | return $self->name ? length($self->name) : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | } | ||||||||||
| 143 | |||||||||||
| 144 | =head1 LICENSE | ||||||||||
| 145 | |||||||||||
| 146 | Copyright (C) 2010 Mark Allen | ||||||||||
| 147 | |||||||||||
| 148 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 149 | under the terms of either: the GNU General Public License as published | ||||||||||
| 150 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 151 | |||||||||||
| 152 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 153 | |||||||||||
| 154 | =head1 AUTHOR | ||||||||||
| 155 | |||||||||||
| 156 | Mark Allen <mrallen1@yahoo.com> | ||||||||||
| 157 | |||||||||||
| 158 | =head1 SEE ALSO | ||||||||||
| 159 | |||||||||||
| 160 | L<Moose>, L<Table::Simple>, L<Table::Simple::Output> | ||||||||||
| 161 | |||||||||||
| 162 | =cut | ||||||||||
| 163 | |||||||||||
| 164 | 7 | __PACKAGE__->meta->make_immutable(); | |||||||||
| 165 | 7 | 1; | |||||||||