]> git.donarmstrong.com Git - debbugs.git/commitdiff
use BUILD to handle correspondent argument; add CARP_TRACE
authorDon Armstrong <don@donarmstrong.com>
Fri, 8 Jun 2018 20:31:07 +0000 (13:31 -0700)
committerDon Armstrong <don@donarmstrong.com>
Fri, 8 Jun 2018 20:31:07 +0000 (13:31 -0700)
Debbugs/Collection/Correspondent.pm
Debbugs/Correspondent.pm

index 76a386f5d1816bb191c456ded230d324d16751fe..43ac8c091aa492b16f701596cdd0cde5f8e1af6d 100644 (file)
@@ -32,45 +32,26 @@ extends 'Debbugs::Collection';
 
 has '+members' => (isa => 'ArrayRef[Debbugs::Correspondent]');
 
-around BUILDARGS => sub {
-    my $orig = shift;
-    my $class = shift;
-
-    my %args;
-    if (@_==1 and ref($_[0]) eq 'HASH') {
-        %args = %{$_[0]};
-    } else {
-        %args = @_;
-    }
-    $args{members} //= [];
-    if (exists $args{correspondent}) {
-        push @{$args{members}},
-            _member_constructor(correspondent => $args{correspondent},
-                                hash_slice(%args,qw(schema constructor_args)),
-                               );
-        delete $args{bugs};
+sub BUILD {
+    my $self = shift;
+    my $args = shift;
+    if (exists $args->{correspondent}) {
+        $self->
+            add($self->_member_constructor(correspondent =>
+                                           $args->{correspondent}));
     }
-    return $class->$orig(%args);
-};
+}
+
 
 sub _member_constructor {
     # handle being called $self->_member_constructor;
-    my $self;
-    if ((@_ % 2) == 1) {
-        $self = shift;
-    }
+    my $self = shift;
     my %args = @_;
     my @return;
-    my $schema;
-    if (exists $args{schema}) {
-        $schema = $args{schema};
-    } elsif (defined $self and $self->has_schema) {
-        $schema = $self->schema;
-    }
     for my $corr (make_list($args{correspondent})) {
        push @return,
            Debbugs::Correspondent->new(name => $corr,
-                                       defined $schema?(schema => $schema):(),
+                                       $self->schema_argument,
                                       );
     }
     return @return;
@@ -80,10 +61,9 @@ around add_by_key => sub {
     my $orig = shift;
     my $self = shift;
     my @members =
-        _member_constructor(correspondent => [@_],
-                            $self->has_schema?(schema => $self->schema):(),
-                            constructor_args => $self->constructor_args,
-                           );
+        $self->_member_constructor(correspondent => [@_],
+                                  $self->schema_argument,
+                                 );
     return $self->$orig(@members);
 };
 
index bb075047d1022662ece4f909a864ec0066c4ef72..0044347955cd3c220ea0b258e7d12e40017e46c3 100644 (file)
@@ -80,6 +80,14 @@ sub submitter_url {
     return $config{web_domain}.'/submitter:'.$self->email;
 }
 
+sub CARP_TRACE {
+    my $self = shift;
+    return 'Debbugs::Correspondent={name='.$self->name.'}';
+}
+
+
+__PACKAGE__->meta->make_immutable;
+
 no Mouse;
 1;