| 1 | # Build::Hopen::Util::Filename - functions for manipulating filenames | ||
| 2 | package Build::Hopen::Util::Filename; | ||
| 3 | use Build::Hopen; | ||
| 4 | use Build::Hopen::Base; | ||
| 5 | |||
| 6 | our $VERSION = '0.000008'; # TRIAL | ||
| 7 | |||
| 8 | use parent 'Exporter'; | ||
| 9 | our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS); | ||
| 10 | BEGIN { | ||
| 11 | @EXPORT = qw(); | ||
| 12 | @EXPORT_OK = qw(obj exe lib); | ||
| 13 | %EXPORT_TAGS = ( | ||
| 14 | default => [@EXPORT], | ||
| 15 | all => [@EXPORT, @EXPORT_OK] | ||
| 16 | ); | ||
| 17 | } | ||
| 18 | |||
| 19 | use Class::Method::Modifiers qw(fresh); | ||
| 20 | use Config; | ||
| 21 | use Build::Hopen::Arrrgs; | ||
| 22 | |||
| 23 | # Docs {{{1 | ||
| 24 | |||
| 25 | =head1 NAME | ||
| 26 | |||
| 27 | Build::Hopen::Util::Filename - functions for manipulating filenames | ||
| 28 | |||
| 29 | =head1 SYNOPSIS | ||
| 30 | |||
| 31 | Nothing is exported by default. Each function is available via an OO | ||
| 32 | interface or a procedural interface. | ||
| 33 | |||
| 34 | =head1 FUNCTIONS | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | # }}}1 | ||
| 39 | |||
| 40 | =head2 obj | ||
| 41 | |||
| 42 | Return the given filename, with the extension of an object file added. | ||
| 43 | Usage: | ||
| 44 | |||
| 45 | Build::Hopen::Util::Filename::obj(filename[, -strip=>true]); # procedural | ||
| 46 | Build::Hopen::Util::Filename->new->obj(fn[, -strip=>true]); # OO | ||
| 47 | |||
| 48 | If C<< -strip => <truthy> >> is given, strip any existing extension first. | ||
| 49 | |||
| 50 | =head2 exe | ||
| 51 | |||
| 52 | Return the given filename, with the extension of an executable file added. | ||
| 53 | Usage and options are the same as L</obj>. | ||
| 54 | |||
| 55 | =head2 lib | ||
| 56 | |||
| 57 | Return the given filename, with the extension of a library file added. | ||
| 58 | Usage and options are the same as L</obj>. | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | # Create obj(), exe(), and lib() in a loop since they share the same skeleton. | ||
| 63 | |||
| 64 | BEGIN { | ||
| 65 | foreach my $lrFunction ([qw(obj _o obj_ext .o)], | ||
| 66 | [qw(exe _exe exe_ext), ''], | ||
| 67 | [qw(lib _a lib_ext .a)]) | ||
| 68 | { | ||
| 69 | fresh $lrFunction->[0] => sub { | ||
| 70 | my (undef, %args) = parameters(__PACKAGE__, [qw(filename; strip)], @_); | ||
| 71 | # __PACKAGE__ => Permit OO interface | ||
| 72 | $args{filename} =~ s/\.[^.]*$// if $args{strip}; | ||
| 73 | return $args{filename} . | ||
| 74 | ($Config{$lrFunction->[1]} // $Config{$lrFunction->[2]} // | ||
| 75 | $lrFunction->[3]); | ||
| 76 | }; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | =head2 new | ||
| 81 | |||
| 82 | Create a new instance for the OO interface. For example: | ||
| 83 | |||
| 84 | my $FN = Build::Hopen::Util::Filename->new; | ||
| 85 | say $fn->obj('hello'); # e.g., "hello.o" or "hello.obj" | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | sub new { bless {}, shift } | ||
| 90 | |||
| 91 | 1; | ||
| 92 | __END__ |