Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Makefile.PL is auto-generated from dist.ini — edit dist.ini for build configur

### Two-layer design

**Perl layer** (`lib/Overload/FileCheck.pm`): Public API — `mock_file_check`, `mock_stat`, `mock_lstat`, `mock_all_file_checks`, `mock_all_from_stat`, and their `unmock_*` counterparts. Manages the mapping from operator names (e.g., '-e') to Perl OP types (e.g., `OP_FTIS`). Provides export groups `:check` (return value constants), `:stat` (stat index constants and helpers like `stat_as_file()`), and `:all`.
**Perl layer** (`lib/Overload/FileCheck.pm`): Public API — `mock_file_check`, `mock_stat`, `mock_all_file_checks`, `mock_all_from_stat`, and their `unmock_*` counterparts. `mock_stat` handles both stat and lstat (there is no separate `mock_lstat`). Manages the mapping from operator names (e.g., '-e') to Perl OP types (e.g., `OP_FTIS`). Provides export groups `:check` (return value constants), `:stat` (stat index constants and helpers like `stat_as_file()`), and `:all`.

**XS layer** (`FileCheck.xs` + `FileCheck.h`): Replaces Perl's default `pp_*` OP handlers with custom ones that call back into Perl. Three handler types: `pp_overload_ft_yes_no` (boolean ops like -e, -f), `pp_overload_ft_int`/`pp_overload_ft_nv` (numeric ops like -s, -M), and `pp_overload_stat` (stat/lstat). `FileCheck.h` contains compatibility macros for Perl 5.14 vs 5.15+ internal API differences.

Expand Down
15 changes: 14 additions & 1 deletion lib/Overload/FileCheck.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ my @STAT_T_IX = qw{
my @CHECK_STATUS = qw{CHECK_IS_FALSE CHECK_IS_TRUE CHECK_IS_NULL FALLBACK_TO_REAL_OP};

my @STAT_HELPERS = qw{ stat_as_directory stat_as_file stat_as_symlink
stat_as_socket stat_as_chr stat_as_block};
stat_as_socket stat_as_chr stat_as_block stat_as_fifo};

our @EXPORT_OK = (
qw{
Expand Down Expand Up @@ -600,6 +600,12 @@ sub stat_as_block {
return _stat_for( S_IFBLK, \%opts );
}

sub stat_as_fifo {
my (%opts) = @_;

return _stat_for( S_IFIFO, \%opts );
}

sub _stat_for {
my ( $type, $opts ) = @_;

Expand Down Expand Up @@ -921,6 +927,8 @@ Available functions are:

=item stat_as_block

=item stat_as_fifo

=back


Expand Down Expand Up @@ -1048,6 +1056,11 @@ view stat_as_directory and L</"Using stat_as_* helpers"> for some sample usages
Create a stat array ref for an empty block device
view stat_as_directory and L</"Using stat_as_* helpers"> for some sample usages

=head2 stat_as_fifo( %OPTS )

Create a stat array ref for a named pipe (FIFO)
view stat_as_directory and L</"Using stat_as_* helpers"> for some sample usages

=head1 Notice

This is a very early development stage and some behavior might change before the release of a more stable build.
Expand Down
9 changes: 9 additions & 0 deletions t/mock-all-from-stat_basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ my $fake_files = {
'regular.file' => stat_as_file( size => 666 ),
'empty.file' => stat_as_file(),
'my.socket' => stat_as_socket(),
'my.fifo' => stat_as_fifo(),
};

# move to DATA
Expand Down Expand Up @@ -134,6 +135,14 @@ __DATA__
-S 'my.socket'
!-s 'my.socket'

# a FIFO (named pipe)
-e 'my.fifo'
!-d 'my.fifo'
!-f 'my.fifo'
-p 'my.fifo'
!-S 'my.fifo'
!-s 'my.fifo'

# a zero stat (stat succeeded with all-zero fields — file exists but has no type)
-e 'zero'
!-f 'zero'
Expand Down
1 change: 1 addition & 0 deletions t/stat-helpers.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ is stat_as_symlink(), [ 0, 0, S_IFLNK, (0) x 10 ], 'stat_as_symlink';
is stat_as_socket(), [ 0, 0, S_IFSOCK, (0) x 10 ], 'stat_as_socket';
is stat_as_chr(), [ 0, 0, S_IFCHR, (0) x 10 ], 'stat_as_chr';
is stat_as_block(), [ 0, 0, S_IFBLK, (0) x 10 ], 'stat_as_block';
is stat_as_fifo(), [ 0, 0, S_IFIFO, (0) x 10 ], 'stat_as_fifo';

if ( $> == 0 ) {
my ($username, $gid) = (getpwuid $>)[0, 3];
Expand Down
Loading