The end result: (in progress)
#!/usr/bin/perl use strict; use MogileFS; use DBI; use DBD::mysql; sub get_dbh { return DBI->connect("DBI:mysql:mogilefs", "mogile", ""); } # create a MogileFS handle for domain "test" my $mg = MogileFS->new( domain => 'test', get_dbh => \&get_dbh, cache_memcached => undef, ); # tells the framework we want to put a new file in the system. # new_file returns an IO::File object (IO::Handle) that's subclassed # by MogileFS and ready for writing. my $fh = $mg->new_file("whitakers_mom"); print $fh "Worddddd\n"; # and when you close it, it sets the flags in the database that makes it # start replicating everywhere: $fh->close;
Implementing close:
sub close { my $self = shift; # is a typeglob # actually close the file $self->SUPER::close; # get a reference to the hash part of the $fh typeglob ref my $href = \%{*$self}; # ... set DB flags based on device/fileid in above $href }GO PERL! :P