Skip to content

Commit

Permalink
make list_windows return list, not print to selected filehandle
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Sep 15, 2024
1 parent b29af62 commit 9c3e636
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Revision history for PDL-DSP-Windows

{{$NEXT}}

- list_windows now returns a list, not print to selected filehandle

0.101 2024-09-11 20:13:59 BST

Fixes:
Expand Down
1 change: 0 additions & 1 deletion META.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"CPAN::Meta" : "2.120900"
},
"requires" : {
"Capture::Tiny" : "0",
"ExtUtils::MakeMaker" : "0",
"File::Spec" : "0",
"Test::More" : "0.96",
Expand Down
2 changes: 0 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ my %WriteMakefileArgs = (
"PDL" => "2.055"
},
"TEST_REQUIRES" => {
"Capture::Tiny" => 0,
"ExtUtils::MakeMaker" => 0,
"File::Spec" => 0,
"Test::More" => "0.96"
Expand All @@ -33,7 +32,6 @@ my %WriteMakefileArgs = (


my %FallbackPrereqs = (
"Capture::Tiny" => 0,
"ExtUtils::MakeMaker" => 0,
"File::Spec" => 0,
"PDL" => "2.055",
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ are case-insensitive.

## list\_windows

list_windows
list_windows STR
print join ", ", list_windows(), "\n"
print join ", ", list_windows(STR), "\n"

`list_windows` prints the names all of the available windows.
`list_windows STR` prints only the names of windows matching the string `STR`.
`list_windows` returns the names all of the available windows.
`list_windows STR` returns only the names of windows matching the
regular expression `STR`.

# METHODS

Expand Down
1 change: 0 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ feature plot => 'Plot windows' => sub {
};

on test => sub {
requires 'Capture::Tiny' => '0';
requires 'Test::More' => '0.96';
};
34 changes: 14 additions & 20 deletions lib/PDL/DSP/Windows.pm
Original file line number Diff line number Diff line change
Expand Up @@ -319,35 +319,29 @@ sub window { PDL::DSP::Windows->new(@_)->samples }

=head2 list_windows
list_windows
list_windows STR
print join ", ", list_windows(), "\n"
print join ", ", list_windows(STR), "\n"
C<list_windows> prints the names all of the available windows.
C<list_windows STR> prints only the names of windows matching the string C<STR>.
C<list_windows> returns the names all of the available windows.
C<list_windows STR> returns only the names of windows matching the
regular expression C<STR>.
=cut

sub list_windows {
my ($expr) = @_;

return sort keys %symmetric_windows if !$expr;
my @match;
if ($expr) {
for my $name ( sort keys %symmetric_windows ) {
if ( $name =~ /$expr/ ) {
push @match, $name;
next;
}

push @match,
map "$name (alias $_)",
grep /$expr/i, @{ $window_aliases{$name} // [] };
for my $name ( sort keys %symmetric_windows ) {
if ( $name =~ /$expr/ ) {
push @match, $name;
next;
}
push @match,
map "$name (alias $_)",
grep /$expr/i, @{ $window_aliases{$name} // [] };
}
else {
@match = sort keys %symmetric_windows;
}

print join( ', ', @match ), "\n";
@match;
}

=head1 METHODS
Expand Down
23 changes: 7 additions & 16 deletions t/list_windows.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use Test::More;
use strict;
use warnings;

use Capture::Tiny 'capture';
use PDL::DSP::Windows qw( list_windows );

my @windows = qw(
Expand Down Expand Up @@ -47,7 +46,13 @@ my @windows = qw(
welch
);

sub do_test (@);
sub do_test (@) {
my $expected = shift;
my @args = @_;
my @got = list_windows(@args);
my $message = @args ? join( ', ', @args ) : 'defaults';
is_deeply \@got, $expected, "list_windows using $message";
}

note 'Can filter windows';
do_test [ grep { /blackman/ } @windows ] => 'blackman';
Expand All @@ -66,18 +71,4 @@ do_test ['tukey'] => qw( tukey nothing else matters welch );
note 'Matches on window aliases';
do_test ['tukey (alias tapered cosine)'] => 'tapered cosine';

sub do_test (@) {
my $expected = shift;
my @args = @_;

my ($stdout) = capture { list_windows(@args) };

chomp $stdout;

my $message = @args ? join( ', ', @args ) : 'defaults';

is $stdout, join( ', ' => @{$expected} ),
"list_windows using $message";
}

done_testing;

0 comments on commit 9c3e636

Please sign in to comment.