App-Followme

 view release on metacpan or  search on metacpan

lib/App/Followme/ConvertPage.pm  view on Meta::CPAN

        $self->update_folder($subfolder);
    }

    return;
}

#----------------------------------------------------------------------
# Write a file, setting folder level metadata

sub write_file {
    my ($self, $filename, $page, $binmode) = @_;

    my $time = ${$self->{data}->build('mdate', $filename)};
    my $new_filename = $self->title_to_filename($filename);

    fio_write_page($new_filename, $page, $binmode);

    unlink($filename) if -e $filename && 
        ! fio_same_file($filename, $new_filename, $self->{case_sensitivity});

    fio_set_date($new_filename, $time);

    return;
}

1;

lib/App/Followme/FIO.pm  view on Meta::CPAN

        }
    }

    return $newest_file;
}

#----------------------------------------------------------------------
# Read a file into a string

sub fio_read_page {
    my ($filename, $binmode) = @_;
    return unless defined $filename;

    local $/;
    my $fd = IO::File->new($filename, 'r');
    return unless $fd;

    binmode($fd, $binmode) if defined $binmode;
    my $page = <$fd>;
    close($fd);

    return $page;
}

#----------------------------------------------------------------------
# Check if two filenames are the same in an os independent way

sub fio_same_file {

lib/App/Followme/FIO.pm  view on Meta::CPAN

    @filenames = sort(@filenames);
    @directories = sort(@directories);

    return (\@filenames, \@directories);
}

#----------------------------------------------------------------------
# Write the page back to the file

sub fio_write_page {
    my ($filename, $page, $binmode) = @_;

	my ($dir, $base) = fio_split_filename($filename);

	if (! -e $dir) {
        die "Couldn't create directory $dir for $filename: $!\n" 
            unless mkdir($dir);
    }
	
    my $fd = IO::File->new($filename, 'w');
    die "Couldn't write $filename: $!\n" unless $fd;

    binmode($fd, $binmode) if defined $binmode;
    print $fd $page;
    close($fd);

    die "Didn't write page $filename\n" unless -e $filename;

    return;
}

1;

lib/App/Followme/FIO.pm  view on Meta::CPAN

Return 1 (Perl true) if a filename matches a Perl pattern in a list of
patterns.

=item $filename = fio_most_recent_file($directory, $patterns, $exclude_index);


Return the most recently modified file in a directory whose name matches
a comma separated list of Unix wildcard patterns. Exclude the index if 
the last argument is true.

=item $str = fio_read_page($filename, $binmode);

Read a file into a string. An the entire file is read from a string, there is no
line at a time IO. This is because files are typically small and the parsing
done is not line oriented. Binmode is an optional parameter that indicates file
type if it is not a plain text file.

=item fio_set_date($filename, $date);

Set the modification date of a file. Date is either in seconds or
is in ISO format.

lib/App/Followme/FIO.pm  view on Meta::CPAN

=item $filename = fio_to_file($directory, $ext);

Convert a directory name to the index file it contains. The extension
is used in the index name. If the directory name is a file name,
return it unchnged.

=item ($filenames, $directories) = fio_visit($top_directory);

Return a list of filenames and directories in a directory,

=item fio_write_page($filename, $str, $binmode);

Write a file from a string. An the entire file is written from a string, there
is no line at a time IO. This is because files are typically small. Binmode is
an optional parameter that indicates file type if it is not a plain text file.

=back

=head1 LICENSE

Copyright (C) Bernie Simon.

lib/App/Followme/Initialize.pm  view on Meta::CPAN

}

#----------------------------------------------------------------------
# Copy a binary file

sub copy_binary {
    my($file, $lines, @args) = @_;
    return if -e $file;

    my $out = IO::File->new($file, 'w') or die "Couldn't write $file: $!\n";
    binmode($out);

    foreach my $line (@$lines) {
        print $out decode_base64($line);
    }

    close($out);
    return;
}

#----------------------------------------------------------------------

share/bundle.pl  view on Meta::CPAN

#----------------------------------------------------------------------
# Append a binary file to the bundle

sub append_binary_file {
    my ($out, $file) = @_;


    my $in = IO::File->new($file, 'r');
    die "Couldn't read $file: $!\n" unless $in;

    binmode $in;
    my $buf;

    while (read($in, $buf, 60*57)) {
        print $out encode_base64($buf);
    }

    close($in);
    return;
}



( run in 0.579 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )