UR::Da...::File(3pm)

πŸ“¦
version 0.470 Β· 2 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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. Use file_list() instead of server() when you wanna load-balance across several NFS servers, for example. βš–οΈ
ok important: you must have either server() or file_list() in your module, but not both. And if both exist, server() takes precedence over file_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 $/ before getline() is called on the file's filehandle. The default record_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_order is 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 in column_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:

  • UR
  • UR::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