[html-formfu] Inflator for NetAddr::IP object

Bill Uhl bill at greenlightnet.com
Thu Jun 14 13:04:17 GMT 2018


Hi,

I am trying to write an inflator that will produce a NetAddr::IP object
from my form input. I have searched for but been unable to find much
information about writing custom inflators. If there are examples or
additional documentation available, links would be greatly appreciated.

I am working on my first Catalyst web site with DBIC and FormFu. I am using
the built-in Catalyst server to display the web pages. The whole thing is
running on a CentOS 7.5 VM on one of my servers.

I took a look at the source for the core inflators and from what I
(mis)understand of the code, the inflator provides an inflator method that
returns on failure or returns the inflated object upon success. I have
written the following but it does not work as I expected.

package HTML::FormFu::Inflator::NetAddr::IP;
use Moose;
use HTML::FormFu::Constants qw( $EMPTY_STR );
use NetAddr::IP;
use namespace::autoclean;

extends 'HTML::FormFu::Inflator';

sub inflator {
    my ( $self, $value ) = @_;

    return if !defined $value || $value eq $EMPTY_STR;

    my $ip = NetAddr::IP->new($value);
    return if !defined $ip;

    return $ip;
}

__PACKAGE__->meta->make_immutable;

1;

With the following form config...

  # Text box for the network subnet address
  - type: Text
    name: subnet
    label: Subnet
    attributes:
      title: Enter the Subnet Address for this network in CIDR format.
    inflators:
      - type: NetAddr::IP
        message: Not a valid subnet address.

Even when I enter a valid address that should be inflatable, such as
10.255.255.0/24,  I get the 'Not a valid subnet address' error message.

Any help or redirection would be appreciated.

Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20180614/bee0759f/attachment.htm>


More information about the HTML-FormFu mailing list