[Dbix-class] inflators / defaltors

Goetz Bock bock+dbixc at blacknet.de
Tue Mar 27 09:10:13 GMT 2007


On Mon, Mar 26 '07 at 21:05, Guillermo Roditi wrote:
> heh. i think i have a good chunk of code for Net::IP inflator /
> deflator at my office. I'll forward to the list tomorrow. i posted the
> code in IRC last friday so if someone has a log you might be able to
> get the shadowpaste link

Castaway on irc still had the url. I will probably not be able to give
it a try today at all, but here is the code:

------------------------------------------------------------------------
package DBIx::Class::InflateColumn::NetIP;

use strict;
use warnings;
use base qw/DBIx::Class/;
use Net::IP;
use Socket qw/inet_aton inet_ntoa/;

__PACKAGE__->load_components(qw/InflateColumn/);

sub register_column {
    my ($self, $column, $info, @rest) = @_;
    $self->next::method($column, $info, @rest);

    if ($info->{is_ipaddress}) {
        $self->inflate_column
            ($column =>
             {
              inflate => sub {
                  my ($value) = @_;
                  Net::IP->new( inet_ntoa($value) );
              },
              deflate => sub {
                  my ($value) = @_;
                  inet_aton($value->ip);
              },
             }
            );
    }
}

1;
------------------------------------------------------------------------
--  
/"\ Goetz Bock at blacknet dot de  --  secure mobile Linux everNETting
\ /       (c) 2007 Creative Commons, Attribution-ShareAlike 2.0 de
 X   [ 1. Use descriptive subjects - 2. Edit a reply for brevity -  ]
/ \  [ 3. Reply to the list - 4. Read the archive *before* you post ]



More information about the Dbix-class mailing list