File Coverage

blib/lib/PGObject/Type/BigFloat.pm
Criterion Covered Total %
statement 38 40 95.0
branch 10 14 71.4
condition 4 5 80.0
subroutine 10 10 100.0
pod 4 4 100.0
total 66 73 90.4


line stmt bran cond sub pod time code
1             package PGObject::Type::BigFloat;
2              
3 4     4   255171 use 5.010;
  4         34  
4 4     4   16 use strict;
  4         8  
  4         76  
5 4     4   15 use warnings;
  4         8  
  4         99  
6 4     4   17 use base qw(Math::BigFloat);
  4         14  
  4         3809  
7 4     4   186427 use PGObject;
  4         14936  
  4         21  
8 4     4   166 use Carp;
  4         7  
  4         1528  
9              
10             =head1 NAME
11              
12             PGObject::Type::BigFloat - Math::BigFloat wrappers for PGObject classes
13              
14             =head1 VERSION
15              
16             Version 2.001
17              
18             =cut
19              
20             our $VERSION = 2.001000;
21              
22             our ($accuracy, $precision, $round_mode, $div_scale);
23              
24             # Globals
25             $accuracy = $precision = undef;
26             $round_mode = 'even';
27             $div_scale = 40;
28              
29             =head1 SYNOPSIS
30              
31             use PGObject::Type::BigFloat;
32             PGObject::Type::BigFloat->register(); # Get all numeric and float types
33              
34             my $self->{foo} = PGObject::Type::BigFloat->new(0);
35              
36             $self->call_dbmethod(funcname => 'bar'); # will use this as a numeric
37            
38              
39             =head1 SUBROUTINES/METHODS
40              
41             =head2 register(registry => 'default', types => ['float4', 'float8', 'numeric'])
42              
43              
44             =cut
45              
46             sub register{
47 5     5 1 1039 my $self = shift @_;
48 5         15 my %args = @_;
49 5 50       12 croak "Can't pass reference to register \n".
50             "Hint: use the class instead of the object" if ref $self;
51 5         8 my $registry = $args{registry};
52 5   100     20 $registry ||= 'default';
53 5         10 my $types = $args{types};
54 5 100 66     21 $types = ['float4', 'float8', 'numeric'] unless defined $types and @$types;
55 5         10 for my $type (@$types){
56 11 50       311 if ($PGObject::VERSION =~ /^1\./){
57 0         0 my $ret =
58             PGObject->register_type(registry => $registry, pg_type => $type,
59             perl_class => $self);
60 0 0       0 return $ret unless $ret;
61             } else {
62 11         30 PGObject::Type::Registry->register_type(
63             registry => $registry, dbtype => $type, apptype => $self
64             );
65             }
66             }
67 5         203 return 1;
68             }
69              
70             =head2 to_db
71              
72             This serializes this into a simple db-friendly form.
73              
74             =cut
75              
76             sub to_db {
77 10     10 1 5784 my $self = shift @_;
78 10 100       22 return undef if $self->is_undef;
79 9         28 return $self->bstr;
80             }
81              
82             =head2 from_db
83              
84             take simple normalized db floats and turn them into numeric representations.
85              
86             =cut
87              
88             sub from_db {
89 10     10 1 10209 my ($self, $value) = @_;
90 10         37 my $obj = "$self"->new($value);
91 10 100       2199 $obj->is_undef(1) if ! defined $value;
92 10         22 return $obj;
93             }
94              
95             =head2 is_undef(optionally $set);
96              
97             Return undef to the db or user interface. Can be set through apps.
98              
99             =cut
100              
101             sub is_undef {
102 11     11 1 17 my ($self, $set) = @_;
103 11 100       26 $self->{_pgobject_undef} = $set if defined $set;
104 11         24 return $self->{_pgobject_undef};
105             }
106              
107             =head1 AUTHOR
108              
109             Chris Travers, C<< >>
110              
111             =head1 BUGS
112              
113             Please report any bugs or feature requests to C, or through
114             the web interface at L. I will be notified, and then you'll
115             automatically be notified of progress on your bug as I make changes.
116              
117              
118              
119              
120             =head1 SUPPORT
121              
122             You can find documentation for this module with the perldoc command.
123              
124             perldoc PGObject::Type::BigFloat
125              
126              
127             You can also look for information at:
128              
129             =over 4
130              
131             =item * RT: CPAN's request tracker (report bugs here)
132              
133             L
134              
135             =item * AnnoCPAN: Annotated CPAN documentation
136              
137             L
138              
139             =item * CPAN Ratings
140              
141             L
142              
143             =item * Search CPAN
144              
145             L
146              
147             =back
148              
149              
150             =head1 ACKNOWLEDGEMENTS
151              
152              
153             =head1 LICENSE AND COPYRIGHT
154              
155             Copyright 2013-2014 Chris Travers.
156              
157             This program is released under the following license: BSD
158              
159              
160             =cut
161              
162             1; # End of PGObject::Type::BigFloat