UR::Da...::File(3pm)
π UR::DataSource::File π
okay bestie, gather round, because we're talking about UR::DataSource::File from the User Contributed Perl Documentation collection (yes it's a 3pm page, we love a perl module moment). It's the parent class for file-based data sources β the blueprint your file-reading data source classes inherit from. β¨
π¨ DEPRECATED π¨
bestie. STOP. This module is deprecated. Like, officially. The vibes have moved on. Use UR::DataSource::Filesystem instead. no cap. π«Ά
β¨ SYNOPSIS β¨
here's the whole aesthetic, copy it, live it:
package MyNamespace::DataSource::MyFile;
class MyNamespace::DataSource::MyFile {
is => ['UR::DataSource::File', 'UR::Singleton'],
};
sub server { '/path/to/file' }
sub delimiter { "\t" }
sub column_order { ['thing_id', 'thing_name', 'thing_color' ] }
sub sort_order { ['thing_id'] }
package main;
class MyNamespace::Thing {
id_by => 'thing_id',
has => [ 'thing_id', 'thing_name', 'thing_color' ],
data_source => 'MyNamespace::DataSource::MyFile',
}
my @objs = MyNamespace::Thing->get(thing_name => 'Bob');
look at her. main character energy fr fr. π
πΈ DESCRIPTION πΈ
so, if your class wants to pull its data out of a regular file, you can build it on a UR::DataSource::File-based data source. The modules that implement these data sources live under the DataSource subdirectory of the application's Namespace β that's just the convention, iykyk. π¦
Besides defining a class for your data source that inherits from UR::DataSource::File, it should have the following methods, either as properties or as functions in the package. Both? both is good. π
βοΈ Configuration βοΈ
These methods decide how your data source is set up. it's giving setup era.
server()βserver()should return a string that's the pathname of the file where the data lives. πfile_list()βfile_list()should return a listref of pathnames pointing at one or more identical files where the data lives. Usefile_list()instead ofserver()when you wanna load-balance across several NFS servers, for example. βοΈ
ok important: you must have eitherserver()orfile_list()in your module, but not both. And if both exist,server()takes precedence overfile_list(). no cap, that's just how she runs.
delimiter()βdelimiter()should return a string representing how the fields in each record get split into columns. Internally this string is interpreted as a regex. The default delimiter is"\s*,\s*", meaning the file is separated by commas. πͺrecord_separator()βrecord_separator()should return a string that gets stored in$/beforegetline()is called on the file's filehandle. The defaultrecord_separator()is"\n", meaning the file's records are separated by newlines. πskip_first_line()βskip_first_line()should return a boolean value. If it's true, the first line of the file is ignored β for example, if that first line defines the columns in the file. πcolumn_order()βcolumn_order()should return a listref of column names in the file.column_orderis required β there is no default. bestie you HAVE to give her this one. πsort_order()β if the data file is sorted in some way,sort_order()should return a listref of column names (which must exist incolumn_order()) by which the file is sorted. This gives the system a hint about how the file is structured, and it's able to make shortcuts when reading the file to speed up data access. The default is to assume the file is not sorted. π₯
𧬠INHERITANCE π§¬
the family tree, short and sweet:
UR::DataSource
π SEE ALSO π
go read these too, bestie:
URUR::DataSource
and that's the whole page, babes π this one's running on perl v5.32.1, dated 2022-01-17, brought to you by the User Contributed Perl Documentation girlies. slay, stay hydrated, and go use UR::DataSource::Filesystem instead. periodt. πβ¨
π¦ where this page comes from
- debian bookworm: libur-perl 0.470+ds-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libur-perl 0.470+ds-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libur-perl 0.470+ds-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms