| 1 | package POSIX::2008; |
| 2 | |
| 3 | use strict; |
| 4 | use warnings; |
| 5 | use Carp (); |
| 6 | use IO::Dir (); |
| 7 | use IO::File (); |
| 8 | |
| 9 | require Exporter; |
| 10 | require 'POSIX/2008/symbols.pl'; # Defines @_constants and @_functions. |
| 11 | |
| 12 | our @_constants; |
| 13 | our @_functions; |
| 14 | |
| 15 | our $VERSION = '0.28'; |
| 16 | our $XS_VERSION = $VERSION; |
| 17 | $VERSION = eval $VERSION; # so "use Module 0.002" won't warn on underscore |
| 18 | |
| 19 | our @ISA = qw(Exporter); |
| 20 | our @EXPORT = (); |
| 21 | our @EXPORT_OK = (@_functions, @_constants); |
| 22 | |
| 23 | our %EXPORT_TAGS = ( |
| 24 | # at: Older Perls don't have variable length lookbehind, thus two regexen |
| 25 | # for functions. |
| 26 | 'at' => [ |
| 27 | grep(/^(?:AT|RENAME|RESOLVE)_/, @_constants), |
| 28 | grep(/at2?$/ && !/^(?:creat|l?stat)$/, @_functions), |
| 29 | ], |
| 30 | 'id' => [grep /^[gs]et.+id$/, @_functions], |
| 31 | 'is' => [grep /^is/, @_functions], |
| 32 | 'rw' => [qw(read write readv writev)], |
| 33 | 'prw' => [qw(pread preadv preadv2 pwrite pwritev pwritev2)], |
| 34 | 'clock' => [ |
| 35 | grep(/^(?:CLOCK_|TIMER_ABSTIME)/, @_constants), |
| 36 | grep(/^clock/, @_functions), |
| 37 | ], |
| 38 | 'errno_h'=> [grep /^E(?!MPTY)[A-Z]+$/, @_constants], |
| 39 | 'fcntl' => [grep /^(?:[FORWX]|FD|POSIX_FADV|SEEK)_/, @_constants], |
| 40 | 'fenv_h' => [grep(/^FE_/, @_constants), grep (/^fe/, @_functions)], |
| 41 | 'fnm' => [grep(/^FNM_/, @_constants), 'fnmatch'], |
| 42 | 'poll' => ['poll', 'ppoll', grep /^(?:POLL|INFTIM)/, @_constants], |
| 43 | 'socket_h' => [ |
| 44 | qw(SCM_RIGHTS SOL_SOCKET SOMAXCONN), |
| 45 | grep(/^(?:AF|MSG|SHUT|SO|SOCK)_/, @_constants), |
| 46 | ], |
| 47 | 'stat_h' => [grep /^(?:S_I|UTIME_)/, @_constants], |
| 48 | 'time_h' => [grep /^(?:CLOCK|TIMER)_/, @_constants], |
| 49 | 'timer' => [grep(/^TIMER_/, @_constants), grep(/^timer_/, @_functions)], |
| 50 | 'utmpx_h' => [ |
| 51 | grep(/_(?:TIME|PROCESS)$/, @_constants), |
| 52 | grep(/^(?:ACCOUNTING|EMPTY|RUN_LVL|UT_UNKNOWN)$/, @_constants), |
| 53 | grep(/utx/, @_functions), |
| 54 | ], |
| 55 | 'confstr' => ['confstr', grep /^_CS_/, @_constants], |
| 56 | 'pathconf' => ['pathconf', grep /^_PC_/, @_constants], |
| 57 | 'sysconf' => ['sysconf', grep /^_SC_/, @_constants], |
| 58 | ); |
| 59 | |
| 60 | my %deprecated = ( |
| 61 | atol => 'atoi', |
| 62 | atoll => 'atoi', |
| 63 | ldiv => 'div', |
| 64 | lldiv => 'div', |
| 65 | fchdir => 'chdir', |
| 66 | fchmod => 'chmod', |
| 67 | fchown => 'chown', |
| 68 | ftruncate => 'truncate', |
| 69 | ); |
| 70 | my %deprecated_warned; |
| 71 | |
| 72 | push @EXPORT_OK, keys %deprecated; |
| 73 | |
| 74 | our $AUTOLOAD; |
| 75 | sub AUTOLOAD { |
| 76 | my ($func) = ($AUTOLOAD =~ /.*::(.*)/); |
| 77 | die "POSIX::2008.xs has failed to load\n" if $func eq 'constant'; |
| 78 | constant($func); |
| 79 | } |
| 80 | |
| 81 | sub import { |
| 82 | my $this = shift; |
| 83 | |
| 84 | require XSLoader; |
| 85 | XSLoader::load('POSIX::2008', $XS_VERSION); |
| 86 | |
| 87 | while (my ($func, $repl) = each %deprecated) { |
| 88 | my $package_func = __PACKAGE__."::${func}"; |
| 89 | my $package_repl = __PACKAGE__."::${repl}"; |
| 90 | no strict 'refs'; |
| 91 | *{$package_func} = sub { |
| 92 | Carp::carp( |
| 93 | "${package_func}() is deprecated, use ${package_repl}() instead" |
| 94 | ) unless $deprecated_warned{$func}++; |
| 95 | &{*{$package_repl}}; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | __PACKAGE__->export_to_level(1, $this, @_); |
| 100 | } |
| 101 | |
| 102 | 1; |