| 1 | package Badger::Data::Type::Class; | ||
| 2 | |||
| 3 | use Badger::Debug ':dump'; | ||
| 4 | use Badger::Class | ||
| 5 | version => 0.01, | ||
| 6 | debug => 0, | ||
| 7 | uber => 'Badger::Class', | ||
| 8 | # words => 'FACETS', | ||
| 9 | constants => 'ARRAY DELIMITER', | ||
| 10 | hooks => { | ||
| 11 | type => \&type, | ||
| 12 | size => \&size, | ||
| 13 | facets => \&facets, | ||
| 14 | }; | ||
| 15 | |||
| 16 | |||
| 17 | sub type { | ||
| 18 | my ($self, $type) = @_; | ||
| 19 | $self->debug("set type to $type") if DEBUG; | ||
| 20 | $self->method( type => $type ); | ||
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | sub size { | ||
| 25 | my ($self, $size) = @_; | ||
| 26 | $self->debug("set size to $size") if DEBUG; | ||
| 27 | $self->method( size => $size ); | ||
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | sub facets { | ||
| 32 | my ($self, $facets) = @_; | ||
| 33 | my $current = $self->var_default( FACETS => [ ] ); | ||
| 34 | |||
| 35 | foreach ($facets, $current) { | ||
| 36 | $_ = [ split DELIMITER ] | ||
| 37 | unless ref eq ARRAY; | ||
| 38 | } | ||
| 39 | |||
| 40 | push(@$current, @$facets); | ||
| 41 | |||
| 42 | $self->debug("merged facets are ", $self->dump_data($facets)) if DEBUG; | ||
| 43 | |||
| 44 | $self->var( FACETS => $current ); | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | 1; | ||
| 49 | |||
| 50 | =head1 NAME | ||
| 51 | |||
| 52 | Badger::Data::Type::Class - metaprogramming module for data type classes | ||
| 53 | |||
| 54 | =head1 SYNOPSIS | ||
| 55 | |||
| 56 | |||
| 57 | =head1 DESCRIPTION | ||
| 58 | |||
| 59 | This module implements a subclass of L<Badger::Class> for creating data | ||
| 60 | types. | ||
| 61 | |||
| 62 | =head1 METHODS | ||
| 63 | |||
| 64 | This module implements the following methods in addition to those inherited | ||
| 65 | from the L<Badger::Class> base class. | ||
| 66 | |||
| 67 | =head2 type($type) | ||
| 68 | |||
| 69 | This method implements the C<type> import hook for specifying the base data | ||
| 70 | type. | ||
| 71 | |||
| 72 | =head2 size($size) | ||
| 73 | |||
| 74 | This method implements the C<type> import hook for specifying the data size. | ||
| 75 | NOTE: subject to change | ||
| 76 | |||
| 77 | =head2 facets($facets) | ||
| 78 | |||
| 79 | This method implements the C<facets> import hook for specifying validation | ||
| 80 | facets for a data type. | ||
| 81 | |||
| 82 | =head1 IMPORT HOOKS | ||
| 83 | |||
| 84 | The following hooks can be specified when the module is imported via C<use>. | ||
| 85 | They correspond directly to the methods documented above. | ||
| 86 | |||
| 87 | =head2 type | ||
| 88 | |||
| 89 | =head2 size | ||
| 90 | |||
| 91 | =head2 facets | ||
| 92 | |||
| 93 | =head1 AUTHOR | ||
| 94 | |||
| 95 | Andy Wardley L<http://wardley.org/> | ||
| 96 | |||
| 97 | =head1 COPYRIGHT | ||
| 98 | |||
| 99 | Copyright (C) 2008-2012 Andy Wardley. All Rights Reserved. | ||
| 100 | |||
| 101 | This module is free software; you can redistribute it and/or | ||
| 102 | modify it under the same terms as Perl itself. | ||
| 103 | |||
| 104 | =head1 SEE ALSO | ||
| 105 | |||
| 106 | L<Badger::Base>, | ||
| 107 | L<Badger::Data::Facet>. | ||
| 108 | |||
| 109 | =cut | ||
| 110 | |||
| 111 | # Local Variables: | ||
| 112 | # mode: perl | ||
| 113 | # perl-indent-level: 4 | ||
| 114 | # indent-tabs-mode: nil | ||
| 115 | # End: | ||
| 116 | # | ||
| 117 | # vim: expandtab shiftwidth=4: |