Catman...:Multi(3pm)

πŸ“¦
version 1.16 Β· 4 versions
, in debian bookworm, ubuntu noble

πŸ’– NAME πŸ’–

Catmandu::Store::File::Multi β€” a store that adds files to multiple stores. Like, one store to rule them all, but the stores are file stores, and there are several of them. Slay. πŸ¦‹


✨ SYNOPSIS ✨

okay bestie, straight into it. Command line first:

# On the Command line

# Configure the File::Multi store with a catmandu.yml file
$ cat catmandu.yml
---
store:
  files1:
   package: File::Simple
   options:
      root: /data1/files
  files1:
   package: File::Simple
   options:
      root: /data1/files_copy
  multi:
   package: File::Multi
   options:
       stores:
           - files1
           - files2
...

# List all the folder in the multi store as YAML
$ catmandu export multi to YAML

# Add a file to the multi store with ID 7890 and stored name data.dat
$ catmandu stream /tmp/data.dat to multi --bag 7890 --id data.dat

# Download a file from the multi store
$ catmandu stream multi --bag 7890 --id data.dat

(and yes, the config file in that example really does define files1 twice, once pointing at /data1/files and once at /data1/files_copy, while the stores: list mentions files1 and files2. That's exactly what the original says, so that's exactly what you get. iykyk πŸ™ˆ)

and now the Perl side πŸ’…:

# In Perl
use Catmandu;

my $store = Catmandu->store('File::Multi' , stores [
    Catmandu->store('Simple', root => '/data1/files') ,
    Catmandu->store('Simple', root => '/data1/files_copy') ,
]);

my $index = $store->index;

$store->index->each(sub {
    my $item = shift;
    printf "%s\n" , $item->{_id};
});

# Add a folder to the multi store
my $item = $store->add({ _id => '1234');

# Retrieve the folder bag
my $files = $store->files(1234);

# Listing of all files
$files->each(sub {
    my $file = shift;

    my $name         = $file->_id;
    my $size         = $file->size;
    my $content_type = $file->content_type;
    my $created      = $file->created;
    my $modified     = $file->modified;

    $file->stream(IO::File->new(">/tmp/$name"), file);
});

# Add a new file
$files->upload(IO::File->new("</tmp/data.dat"),"data.dat");

# Retrieve a file
my $file = $files->get('data.dat');

# Stream the file to an IO::Handle
$container->stream(IO::File->new(">/tmp/data.dat"),$file);

# This will delete the folder and files
$index->delete('1234');
fr fr, copy these snippets character for character β€” including the lil quirks like my $item = $store->add({ _id => '1234'); and $container->stream(...). not my business to fix them, they're part of the page. πŸ™ˆ

🌸 DESCRIPTION 🌸

Catmandu::Store::File::Multi is a combination of many Catmandu::FileStore-s as one access point. One front door, many closets. πŸšͺ✨ The Multi store inherits all the methods from Catmandu::FileStore.

By default, the Multi store tries to update records in all configured backend stores. Importing, exporting, delete and drop will be executed against all backend stores when possible. The way that it just… does the thing everywhere at once? obsessed. πŸ‘‘


πŸŽ€ METHODS πŸŽ€

new(stores => [...])

Create a new Catmandu::Store::File::Multi. The stores configuration parameter contains an array of references to Catmandu::FileStore-s β€” either based on their name in a configuration file, or as instances. you're basically handing it a lil squad of stores and it's like "okay bet, i got all of you". 🫢


πŸ’œ INHERITED METHODS πŸ’œ

This Catmandu::FileStore implements:

  • Catmandu::FileStore
  • Catmandu::Droppable

The index Catmandu::Bag in this Catmandu::Store implements:

  • Catmandu::Bag
  • Catmandu::FileBag::Index
  • Catmandu::Droppable

The file Catmandu::Bag in this Catmandu::Store implements:

  • Catmandu::Bag
  • Catmandu::FileBag
  • Catmandu::Droppable

look at that inheritance tree. main character energy from top to bottom. 🌈⭐


πŸ”₯ SEE ALSO πŸ”₯

  • Catmandu::Store::File::Multi::Index, Catmandu::Store::File::Multi::Bag, Catmandu::Store::Multi , Catmandu::Plugin::SideCar

and that's a wrap bestie πŸŽ€ this whole page came from the User Contributed Perl Documentation for Catman...:Multi(3pm), and it's documenting perl v5.36.0, dated 2022-12-10. periodt. πŸ’–βœ¨

πŸ“¦ where this page comes from