File Coverage

blib/lib/Rose/DB/Object/Metadata/Column/Character.pm
Criterion Covered Total %
statement 15 33 45.4
branch 0 14 0.0
condition n/a
subroutine 5 8 62.5
pod 2 3 66.6
total 22 58 37.9


line stmt bran cond sub pod time code
1             package Rose::DB::Object::Metadata::Column::Character;
2              
3 3     3   23 use strict;
  3         6  
  3         87  
4              
5 3     3   15 use Carp();
  3         7  
  3         49  
6              
7 3     3   17 use Rose::Object::MakeMethods::Generic;
  3         5  
  3         65  
8 3     3   88 use Rose::DB::Object::MakeMethods::Generic;
  3         9  
  3         28  
9              
10 3     3   99 use Rose::DB::Object::Metadata::Column::Scalar;
  3         7  
  3         1663  
11             our @ISA = qw(Rose::DB::Object::Metadata::Column::Scalar);
12              
13             our $VERSION = '0.803';
14              
15 0     0 1   sub type { 'character' }
16              
17             foreach my $type (__PACKAGE__->available_method_types)
18             {
19             __PACKAGE__->method_maker_type($type => 'character')
20             }
21              
22             sub parse_value
23             {
24 0     0 1   my ($self, $db, $value) = @_;
25              
26 0 0         my $length = $self->length or return $value;
27              
28 0 0         if(length($value) > $length)
29             {
30 0           my $overflow = $self->overflow;
31            
32 0 0         if($overflow eq 'fatal')
    0          
33             {
34 0           local $Carp::CarpLevel = $Carp::CarpLevel + 1;
35 0           Carp::croak $self->parent->class, ': Value for ', $self->name, ' is too long. Maximum ',
36 0 0         "length is $length character@{[ $length == 1 ? '' : 's' ]}. ",
37             "Value is ", length($value), " characters: $value";
38             }
39             elsif($overflow eq 'warn')
40             {
41 0           local $Carp::CarpLevel = $Carp::CarpLevel + 1;
42 0           Carp::carp $self->parent->class, ': Value for ', $self->name, ' is too long. Maximum ',
43 0 0         "length is $length character@{[ $length == 1 ? '' : 's' ]}. ",
44             "Value is ", length($value), " characters: $value";
45             }
46             }
47              
48 0           return sprintf("%-*s", $length, substr($value, 0, $length));
49             }
50              
51             *format_value = \&parse_value;
52              
53             sub init_with_dbi_column_info
54             {
55 0     0 0   my($self, $col_info) = @_;
56              
57 0           $self->SUPER::init_with_dbi_column_info($col_info);
58              
59 0 0         if(defined $col_info->{'CHAR_OCTET_LENGTH'})
60             {
61 0           $self->length($col_info->{'CHAR_OCTET_LENGTH'});
62             }
63              
64 0           return;
65             }
66              
67             1;
68              
69             __END__
70              
71             =head1 NAME
72              
73             Rose::DB::Object::Metadata::Column::Character - Character column metadata.
74              
75             =head1 SYNOPSIS
76              
77             use Rose::DB::Object::Metadata::Column::Character;
78              
79             $col = Rose::DB::Object::Metadata::Column::Character->new(...);
80             $col->make_methods(...);
81             ...
82              
83             =head1 DESCRIPTION
84              
85             Objects of this class store and manipulate metadata for character columns in a database. Column metadata objects store information about columns (data type, size, etc.) and are responsible for creating object methods that manipulate column values.
86              
87             This class inherits from L<Rose::DB::Object::Metadata::Column::Scalar>. Inherited methods that are not overridden will not be documented a second time here. See the L<Rose::DB::Object::Metadata::Column::Scalar> documentation for more information.
88              
89             =head1 METHOD MAP
90              
91             =over 4
92              
93             =item C<get_set>
94              
95             L<Rose::DB::Object::MakeMethods::Generic>, L<character|Rose::DB::Object::MakeMethods::Generic/character>, ...
96              
97             =item C<get>
98              
99             L<Rose::DB::Object::MakeMethods::Generic>, L<character|Rose::DB::Object::MakeMethods::Generic/character>, ...
100              
101             =item C<get_set>
102              
103             L<Rose::DB::Object::MakeMethods::Generic>, L<character|Rose::DB::Object::MakeMethods::Generic/character>, ...
104              
105             =back
106              
107             See the L<Rose::DB::Object::Metadata::Column|Rose::DB::Object::Metadata::Column/"MAKING METHODS"> documentation for an explanation of this method map.
108              
109             =head1 OBJECT METHODS
110              
111             =over 4
112              
113             =item B<parse_value DB, VALUE>
114              
115             If C<length> is defined, returns VALUE truncated to a maximum of C<length> characters, or padding with spaces to be exactly C<length> characters long. DB is a L<Rose::DB> object that may be as part of the parsing process. Both arguments are required.
116              
117             =item B<type>
118              
119             Returns "character".
120              
121             =back
122              
123             =head1 AUTHOR
124              
125             John C. Siracusa (siracusa@gmail.com)
126              
127             =head1 LICENSE
128              
129             Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is
130             free software; you can redistribute it and/or modify it under the same terms
131             as Perl itself.