[Bast-commits] r3441 - in trunk/DBIx-Class-InflateColumn-IP:
lib/DBIx/Class/InflateColumn t/lib/DBICTest/Schema
ilmari at dev.catalyst.perl.org
ilmari at dev.catalyst.perl.org
Wed May 30 15:07:20 GMT 2007
Author: ilmari
Date: 2007-05-30 15:07:19 +0100 (Wed, 30 May 2007)
New Revision: 3441
Modified:
trunk/DBIx-Class-InflateColumn-IP/lib/DBIx/Class/InflateColumn/IP.pm
trunk/DBIx-Class-InflateColumn-IP/t/lib/DBICTest/Schema/Host.pm
Log:
Add default data type to address format mapping
Modified: trunk/DBIx-Class-InflateColumn-IP/lib/DBIx/Class/InflateColumn/IP.pm
===================================================================
--- trunk/DBIx-Class-InflateColumn-IP/lib/DBIx/Class/InflateColumn/IP.pm 2007-05-30 12:01:21 UTC (rev 3440)
+++ trunk/DBIx-Class-InflateColumn-IP/lib/DBIx/Class/InflateColumn/IP.pm 2007-05-30 14:07:19 UTC (rev 3441)
@@ -86,7 +86,8 @@
return unless defined $info->{'is_ip'};
- my $ip_format = $info->{ip_format} || $self->ip_format || 'addr';
+ my $ip_format = $info->{ip_format} || _default_format($info->{data_type})
+ || $self->ip_format || 'addr';
my $ip_class = $info->{ip_class} || $self->ip_class || 'NetAddr::IPf';
eval "use $ip_class";
@@ -102,6 +103,19 @@
);
}
+my @format_map = (
+ { type => qr/^int/i, format => 'numeric' },
+ { type => qr{^(?:inet|cidr)$}i, format => 'cidr' },
+);
+
+sub _default_format {
+ my ($type) = @_;
+
+ for my $match (@format_map) {
+ return $match->{format} if $type =~ $match->{type};
+ }
+}
+
=head1 AUTHOR
Dagfinn Ilmari Mannsåker, C<< <ilmari at ilmari.org> >>
Modified: trunk/DBIx-Class-InflateColumn-IP/t/lib/DBICTest/Schema/Host.pm
===================================================================
--- trunk/DBIx-Class-InflateColumn-IP/t/lib/DBICTest/Schema/Host.pm 2007-05-30 12:01:21 UTC (rev 3440)
+++ trunk/DBIx-Class-InflateColumn-IP/t/lib/DBICTest/Schema/Host.pm 2007-05-30 14:07:19 UTC (rev 3441)
@@ -15,7 +15,6 @@
data_type => 'integer',
is_nullable => 0,
is_ip => 1,
- ip_format => 'numeric',
}
);
More information about the Bast-commits
mailing list