1 package DBIx::Class::InflateColumn::IP;
6 our $VERSION = '0.02000';
8 use base qw/DBIx::Class/;
9 __PACKAGE__->mk_classdata(ip_format => 'addr');
10 __PACKAGE__->mk_classdata(ip_class => 'NetAddr::IP');
14 DBIx::Class::InflateColumn::IP - Auto-create NetAddr::IP objects from columns.
18 Load this component and declare columns as IP addresses with the
22 __PACKAGE__->load_components(qw/InflateColumn::IP Core/);
23 __PACKAGE__->add_columns(
25 data_type => 'integer',
28 ip_format => 'numeric',
33 __PACKAGE__->load_components(qw/InflateColumn::IP Core/);
34 __PACKAGE__->add_columns(
36 data_type => 'varchar',
44 Then you can treat the specified column as a NetAddr::IP object.
46 print 'IP address: ', $host->ip_address->addr;
47 print 'Address type: ', $host->ip_address->iptype;
55 =item Arguments: $class
59 Gets/sets the address class that the columns should be inflated into.
60 The default class is NetAddr::IP.
66 =item Arguments: $format
70 Gets/sets the name of the method used to deflate the address for the
71 database. This must return a value suitable for C<$ip_class->new(); The
72 default format is C<addr>, which returns the address in dotted-quad
73 notation. See L<NetAddr::IP/Methods> for suitable values.
75 =head2 register_column
77 Chains with L<DBIx::Class::Row/register_column>, and sets up IP address
78 columns appropriately. This would not normally be called directly by end
84 my ($self, $column, $info, @rest) = @_;
85 $self->next::method($column, $info, @rest);
87 return unless defined $info->{'is_ip'};
89 my $ip_format = $info->{ip_format} || $self->ip_format || 'addr';
90 my $ip_class = $info->{ip_class} || $self->ip_class || 'NetAddr::IPf';
93 $self->throw_exception("Error loading $ip_class: $@") if $@;
94 $self->throw_exception("Format '$ip_format' not supported by $ip_class")
95 unless $ip_class->can($ip_format);
97 $self->inflate_column(
99 inflate => sub { return $ip_class->new(shift); },
100 deflate => sub { return scalar shift->$ip_format; },
107 Dagfinn Ilmari Mannsåker, C<< <ilmari at ilmari.org> >>
111 Please report any bugs or feature requests to
112 C<bug-dbix-class-inflatecolumn-ip at rt.cpan.org>, or through the web interface at
113 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-InflateColumn-IP>.
114 I will be notified, and then you'll automatically be notified of progress on
115 your bug as I make changes.
119 You can find documentation for this module with the perldoc command.
121 perldoc DBIx::Class::InflateColumn::IP
123 You can also look for information at:
127 =item * AnnoCPAN: Annotated CPAN documentation
129 L<http://annocpan.org/dist/DBIx-Class-InflateColumn-IP>
133 L<http://cpanratings.perl.org/d/DBIx-Class-InflateColumn-IP>
135 =item * RT: CPAN's request tracker
137 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-InflateColumn-IP>
141 L<http://search.cpan.org/dist/DBIx-Class-InflateColumn-IP>
147 L<DBIx::Class>, L<NetAddr::IP>
149 =head1 COPYRIGHT & LICENSE
151 Copyright 2007 Dagfinn Ilmari Mannsåker, all rights reserved.
153 This program is free software; you can redistribute it and/or modify it
154 under the same terms as Perl itself.
158 1; # End of DBIx::Class::InflateColumn::IP