#$self->{'Hash'} = shift;
my $newhash = shift;
$self->{'Hash'} = { map { $_ => $newhash->{$_} } qw(svcnum svcpart) };
- $self->setdefault;
+
+ $self->setdefault( $self->_fieldhandlers );
+
$self->{'Hash'}{$_} = $newhash->{$_}
foreach grep { defined($newhash->{$_}) && length($newhash->{$_}) }
keys %$newhash;
$self;
}
+#empty default
+sub _fieldhandlers { (); }
+
sub virtual_fields {
# This restricts the fields based on part_svc_column and the svcpart of
my $columnname = $part_svc_column->columnname;
my $columnvalue = $part_svc_column->columnvalue;
- if ( exists( $coderef->{$columnname} ) ) {
- &{ $coderef->{$columnname} }( $self, $columnvalue);
- } else {
- $self->setfield( $columnname, $columnvalue );
- }
+ $columnvalue = &{ $coderef->{$columnname} }( $self, $columnvalue )
+ if exists( $coderef->{$columnname} );
+ $self->setfield( $columnname, $columnvalue );
}
sub table { 'svc_acct'; }
+sub _fieldhandlers {
+ #false laziness with edit/svc_acct.cgi
+ 'usergroup' => sub {
+ my $usergroup = shift;
+ if ( ref($usergroup) eq 'ARRAY' ) {
+ $usergroup;
+ } elsif ( length($usergroup) ) {
+ [ split(/\s*,\s*/, $usergroup) ];
+ } else {
+ [];
+ }
+ },
+}
+
=item insert [ , OPTION => VALUE ... ]
Adds this account to the database. If there is an error, returns the error,
}
$svc_acct->set_default_and_fixed( {
- 'usergroup' => sub { @groups = split(',', shift ); },
+ #false laziness w/svc-acct::_fieldhandlers
+ 'usergroup' => sub { return $_[0] if ref($_[0]) eq 'ARRAY';
+ @groups = split(/\s*,\s*/, shift );
+ \@groups;
+ },
} );
}