File Coverage

blib/lib/Array/Merge/Unique.pm
Criterion Covered Total %
statement 24 24 100.0
branch 8 8 100.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 40 40 100.0


line stmt bran cond sub pod time code
1             package Array::Merge::Unique;
2              
3 2     2   203379 use 5.006;
  2         6  
4 2     2   9 use strict;
  2         4  
  2         42  
5 2     2   10 use warnings;
  2         4  
  2         102  
6              
7 2     2   744 use Import::Export;
  2         32337  
  2         13  
8             our $VERSION = '1.01';
9              
10 2     2   130 use base qw/Import::Export/;
  2         3  
  2         442  
11              
12             our %EX = (
13             unique_array => [qw/all/]
14             );
15              
16             sub unique_array {
17 3     3 1 191292 my (@dataset, %u);
18             @dataset = grep {
19 3 100       6 my $k = ref $_ ? $_ + 0 : $_;
  18         20  
20 18 100       31 !$u{$k} && do { $u{$k} = 1; $_ }
  10         12  
  10         16  
21             } _aoaoaoa(@_);
22 3 100       11 return wantarray ? @dataset : \@dataset;
23             }
24              
25             sub _aoaoaoa {
26 9 100   9   14 return map { ref $_ eq 'ARRAY' ? _aoaoaoa(@{ $_ }) : $_ } @_;
  24         39  
  6         9  
27             }
28              
29             1;
30              
31             =head1 NAME
32              
33             Array::Merge::Unique - Merge those arrays uniquely
34              
35             =head1 VERSION
36              
37             Version 1.01
38              
39             =cut
40              
41             =head1 SYNOPSIS
42              
43             Quick summary of what the module does.
44              
45             use Array::Merge::Unique qw/unique_array/;
46              
47             my $arrayref = unique_array([qw/one two three/], qw/one two/);
48             my @array = unique_array([qw/one two three/], qw/one two/);
49              
50             =head1 EXPORT
51              
52             =head2 unique_array
53              
54             This module exports a single method unique_array that accepts multiple Arrays and
55             merges them uniquely by value or reference.
56              
57             my $ref = { a => "b" };
58             my $arrayref = unique_array([qw/one two three/, $ref], qw/one two/, $ref); # qw/one two three/, $ref
59              
60             =head1 AUTHOR
61              
62             Robert Acock, C<< >>
63              
64             =head1 BUGS
65              
66             Please report any bugs or feature requests to C, or through
67             the web interface at L. I will be notified, and then you'll
68             automatically be notified of progress on your bug as I make changes.
69              
70             =head1 SUPPORT
71              
72             You can find documentation for this module with the perldoc command.
73              
74             perldoc Array::Merge::Unique
75              
76             You can also look for information at:
77              
78             =over 4
79              
80             =item * RT: CPAN's request tracker (report bugs here)
81              
82             L
83              
84             =item * Search CPAN
85              
86             L
87              
88             =back
89              
90             =head1 ACKNOWLEDGEMENTS
91              
92             =head1 LICENSE AND COPYRIGHT
93              
94             Copyright 2017->2025 Robert Acock.
95              
96             This program is free software; you can redistribute it and/or modify it
97             under the terms of the the Artistic License (2.0). You may obtain a
98             copy of the full license at:
99              
100             L
101              
102             Any use, modification, and distribution of the Standard or Modified
103             Versions is governed by this Artistic License. By using, modifying or
104             distributing the Package, you accept this license. Do not use, modify,
105             or distribute the Package, if you do not accept this license.
106              
107             If your Modified Version has been derived from a Modified Version made
108             by someone other than you, you are nevertheless required to ensure that
109             your Modified Version complies with the requirements of this license.
110              
111             This license does not grant you the right to use any trademark, service
112             mark, tradename, or logo of the Copyright Holder.
113              
114             This license includes the non-exclusive, worldwide, free-of-charge
115             patent license to make, have made, use, offer to sell, sell, import and
116             otherwise transfer the Package with respect to any patent claims
117             licensable by the Copyright Holder that are necessarily infringed by the
118             Package. If you institute patent litigation (including a cross-claim or
119             counterclaim) against any party alleging that the Package constitutes
120             direct or contributory patent infringement, then this Artistic License
121             to you shall terminate on the date that such litigation is filed.
122              
123             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
124             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
125             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
126             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
127             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
128             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
129             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
130             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
131              
132             =cut
133              
134             1; # End of Array::Merge::Unique