1 / 10

Devel::AssertOS

Devel::AssertOS. What platform is my code running on?. Devel::AssertOS. my($name, undef, $uid, $gid) = getpwent();. my($mode, $file_uid, $file_gid) = (stat($file))[2,4,5];. The problem. my $is_writeable = $mode & ( S_IWOTH | (($userid == $file_uid) ? S_IWUSR : 0) |

naoko
Download Presentation

Devel::AssertOS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Devel::AssertOS What platform is my code running on?

  2. Devel::AssertOS my($name, undef, $uid, $gid) = getpwent(); my($mode, $file_uid, $file_gid) = (stat($file))[2,4,5]; The problem my $is_writeable = $mode & ( S_IWOTH | (($userid == $file_uid) ? S_IWUSR : 0) | ($UIDinGID{$file_gid}{$userid} ? S_IWGRP : 0) ); my $error = `$^X $file 2>&1`;

  3. Devel::AssertOS At the top of Makefile.PL: use lib ‘inc’; use Devel::AssertOS qw(Unix); The Solution! Your module now won’t even try to build anywhere else And the CPAN testers will shut the hell up about it

  4. Devel::AssertOS Or maybe you need to run on something BSDish: use lib ‘inc’; use Devel::AssertOS qw(FreeBSD NetBSD OpenBSD); More Solution! Dissolves twice the code of other modules! Or you need a particular OS vendor: use lib ‘inc’; use Devel::AssertOS qw(Sun);

  5. Devel::AssertOS Or you need a particular feature: use lib ‘inc’; use Devel::AssertOS qw(OSFeatures::POSIXShellRedirection); And some other useful tentacles! The use-devel-assertos script will do all this for you

  6. Devel::CheckOS Take different paths through the code depending on platform use Devel::CheckOS qw(os_is); … sub get_users { if(os_is(‘MicrosoftWindows’)) { eval ‘use Win32’; … } elsif(os_is(‘Unix’)) { … … getpwent(); … } } Detecting the platform from within your code

  7. 48 modules for such a simple task!?!? But Dave, why not just use $^O?

  8. 48 modules for such a simple task!?!? Because this is how to detect Unix: sub os_is { $^O =~ /^( aix | bsdos | dgux | dragonfly | dynixptx | freebsd | linux | hpux | irix | darwin | machten | openbsd | netbsd | dec_osf | svr4 | svr5 | sco_sv | unicos | unicosmk | solaris | sunos | interix )$/x ? 1 : 0; } You don’t want to maintain this in lots of different places. You will get it wrong. But Dave, why not just use $^O?

  9. 48 modules for such a simple task!?!? Because this is how to detect Unix: sub os_is { $^O =~ /^( aix | bsdos | dgux | dragonfly | dynixptx | freebsd | linux | hpux | irix | darwin | machten | openbsd | netbsd | dec_osf | svr4 | svr5 | sco_sv | unicos | unicosmk | solaris | sunos | interix )$/x ? 1 : 0; } You don’t want to maintain this in lots of different places. You will get it wrong. But Dave, why not just use $^O? I probably have too, but at least there’s just one place to report and fix the bugs now.

  10. See also • Devel::CheckLib (not yet finished) • Probe::Perl • The perlport manpage

More Related