aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311.pm
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-04-17 12:31:04 +0100
committerStruan Donald <struan@exo.org.uk>2018-04-17 13:41:32 +0100
commitf65ecc75c0899b027ad549d92dc28311c313b2d0 (patch)
tree1a9fce7d86efa380831b6628bf7c577c38fdbefb /perllib/Open311.pm
parente03c3f4251e12043dcdb5497885e18e10bca8782 (diff)
[Open311] correctly handle one word names when splitting
If a name only had a single word we were failing to split it and not setting `first_name`. Also refactor splitting out to a function so the regex is only in one place.
Diffstat (limited to 'perllib/Open311.pm')
-rw-r--r--perllib/Open311.pm12
1 files changed, 10 insertions, 2 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index a65e19fa6..4ec0679af 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -126,7 +126,7 @@ sub _populate_service_request_params {
$description = $problem->detail;
}
- my ( $firstname, $lastname ) = ( $problem->name =~ /(\w+)\.?\s+(.+)/ );
+ my ( $firstname, $lastname ) = $self->split_name( $problem->name );
my $params = {
description => $description,
@@ -338,7 +338,7 @@ sub _populate_service_request_update_params {
my $comment = shift;
my $name = $comment->name || $comment->user->name;
- my ( $firstname, $lastname ) = ( $name =~ /(\w+)\.?\s+(.+)/ );
+ my ( $firstname, $lastname ) = $self->split_name( $name );
$lastname ||= '-';
# fall back to problem state as it's probably correct
@@ -410,6 +410,14 @@ sub _populate_service_request_update_params {
return $params;
}
+sub split_name {
+ my ( $self, $name ) = @_;
+
+ my ( $first, $last ) = ( $name =~ /(\w+)(?:\.?\s+(.+))?/ );
+
+ return ( $first, $last );
+}
+
sub _get {
my $self = shift;
my $path = shift;