```{index} single: FFI::Build::File::Base ``` # FFI::Build::File::Base Base class for File::Build files ## VERSION version 2.12 ## SYNOPSIS Create your own file class ```perl package FFI::Build::File::Foo; use parent qw( FFI::Build::File::Base ); use constant default_suffix => '.foo'; use constant default_encoding => ':utf8'; ``` Use it: ```perl # use an existing file in the filesystem my $file = FFI::Build::File::Foo->new('src/myfile.foo'); # generate a temp file with provided content # file will be deletd when $file falls out of scope. my $file = FFI::Build::File::Foo->new(\'content for a temp foo'); ``` ## DESCRIPTION This class is the base class for other `FFI::Build::File::*` classes. ## CONSTRUCTOR ### new ```perl my $file = FFI::Build::File::Base->new(\$content, %options); my $file = FFI::Build::File::Base->new($filename, %options); ``` Create a new instance of the file class. You may provide either the content of the file as a scalar reference, or the path to an existing filename. Options: - base The base name for any temporary file `ffi_build_` by default. - build The [FFI::Build](../../Build.md) instance to use. - dir The directory to store any temporary file. - platform The [FFI::Build::Platform](../Platform.md) instance to use. ## METHODS ### default\_suffix ```perl my $suffix = $file->default_suffix; ``` **MUST** be overridden in the subclass. This is the standard extension for the file type. `.c` for a C file, `.o` or `.obj` for an object file depending on platform. etc. ### default\_encoding ```perl my $encoding = $file->default_encoding; ``` **MUST** be overridden in the subclass. This is the passed to `binmode` when the file is opened for reading or writing. ### accept\_suffix ```perl my @suffix_list = $file->accept_suffix; ``` Returns a list of regexes that recognize the file type. ### path ```perl my $path = $file->path; ``` The full or relative path to the file. ### basename ```perl my $basename = $file->basename; ``` The base filename part of the path. ### dirname ```perl my $dir = $file->dirname; ``` The directory part of the path. ### is\_temp ```perl my $bool = $file->is_temp; ``` Returns true if the file is temporary, that is, it will be deleted when the file object falls out of scope. You can call `keep`, to keep the file. ### platform ```perl my $platform = $file->platform; ``` The [FFI::Build::Platform](../Platform.md) instance used for this file object. ### build ```perl my $build = $file->build; ``` The [FFI::Build](../../Build.md) instance used for this file object, if any. ### native ```perl my $path = $file->native; ``` Returns the operating system native version of the filename path. On Windows, this means that forward slash `\` is used instead of backslash `/`. ### slurp ```perl my $content = $file->slurp; ``` Returns the content of the file. ### keep ```perl $file->keep; ``` Turns off the temporary flag on the file object, meaning it will not automatically be deleted when the file object is deallocated or falls out of scope. ### build\_item ```perl $file->build_item; ``` Builds the file into its natural output type, usually an object file. It returns a new file instance, or if the file is an object file then it returns empty list. ### build\_all ```perl $file->build_all; ``` If implemented the file in question can directly create a shared or dynamic library without needing a link step. This is useful for languages that have their own build systems. ### needs\_rebuild ```perl my $bool = $file->needs_rebuild ``` ### ld ## AUTHOR Author: Graham Ollis Contributors: Bakkiaraj Murugesan (bakkiaraj) Dylan Cali (calid) pipcet Zaki Mughal (zmughal) Fitz Elliott (felliott) Vickenty Fesunov (vyf) Gregor Herrmann (gregoa) Shlomi Fish (shlomif) Damyan Ivanov Ilya Pavlov (Ilya33) Petr Písař (ppisar) Mohammad S Anwar (MANWAR) Håkon Hægland (hakonhagland, HAKONH) Meredith (merrilymeredith, MHOWARD) Diab Jerius (DJERIUS) Eric Brine (IKEGAMI) szTheory José Joaquín Atria (JJATRIA) Pete Houston (openstrike, HOUSTON) Lukas Mai (MAUKE) ## COPYRIGHT AND LICENSE This software is copyright (c) 2015-2022 by Graham Ollis. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.