Michael Schilli > Trash-Park-0.03 > Trash::Park



Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  


Trash::Park - Store deleted files safely with querying capability


      # Command line:
    $ trashpark some/file/somewhere.dat
    $ trashpark -l

      # API
    use Trash::Park;

    my $trasher = Trash::Park->new();

      # Move foo.dat to trash can

      # List content of trashcan
    for my $item (@{$trasher->history()}) {
        print $item->as_string(), "\n";

      # Expire items with move dates older than 3 days
    $trasher->expire(3 * 24 * 3600);


Trash::Park helps removing files by hiding them in a safe location and querying details of these parking moves.

Trash::Park comes with a command line utility, trashpark.



Construct a new trasher object. By default the trashing depot will be created under ~/.trashpark. An alternative location can be specified using the trash_dir parameter:

    my $trasher = Trash::Park->new(
        trash_dir => "/tmp/trashdir",

The .trashpark directory contains the following file structure:


index/trash contains meta data on parked files in comma separated format (in fact, it's a DBD::CSV database):

    # index.csv
    # file,move-date,mover,perm

trash() puts a file or a directory into the trash can. Note that if you trash a directory, all files are moved to the trash recursively. All files are stored under their full path name. However, no hierarchical directory or link information gets preserved, only single (regular) files are moved, directories and symbolic link get deleted.


Get a complete history of trash moves. Returns a reference to an array of Trash::Park::Element objects, each of which represents a trashed file:

    my $history = $trasher->history();

    for my $item (@$history) {

        print $item->file(), "\n";
        print $item->mode(), "\n";
        print $item->uid(), "\n";
        print $item->move_time(), "\n";

          # Or:

          # Or, print the full path to the trashed file:
        print $trasher->repo() . $item->file(), "\n";

Remove all entries from the trash can older than $expire_time in seconds.


Clear out the entire trash can.


Return the top directory of the the repository. This is where the the deleted files are saved under the original path information. If you trash a file named "/tmp/foobar", it will show up under $trasher->repo() . "/tmp/foobar".





2005, Mike Schilli <cpan@perlmeister.com>

syntax highlighting: