Skip to content

Commit

Permalink
use mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Jun 5, 2008
1 parent 0d77f26 commit 067ab0e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 74 deletions.
8 changes: 4 additions & 4 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use inc::Module::Install;

all_from ('lib/Config/INI.pm');
requires ('Carp' => 0.000); # sure, it's core, but let's be thorough
requires ('IO::File' => 0.000); # minimum version unknown
requires ('IO::String' => 0.000); # minimum version unknown
all_from('lib/Config/INI.pm');
requires('Carp' => 0.000); # sure, it's core, but let's be thorough
requires('Mixin::Linewise::Readers' => 0.001); # first version
requires('Mixin::Linewise::Writers' => 0.001); # first version

extra_tests;

Expand Down
36 changes: 3 additions & 33 deletions lib/Config/INI/Reader.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

use strict;

use warnings;
package Config::INI::Reader;
use Mixin::Linewise::Readers;

=head1 NAME
Expand All @@ -13,7 +13,7 @@ version 0.012
=cut

$Config::INI::Reader::VERSION = '0.012';
our $VERSION = '0.012';

=head1 SYNOPSIS
Expand Down Expand Up @@ -83,42 +83,12 @@ All throw an exception when they encounter an error.
Given a filename, this method returns a hashref of the contents of that file.
=cut

sub read_file {
my ($invocant, $filename) = @_;

# Check the file
Carp::croak "no filename specified" unless $filename;
Carp::croak "file '$filename' does not exist" unless -e $filename;
Carp::croak "'$filename' is not a plain file" unless -f _;

# Slurp in the file
my $handle = IO::File->new($filename, '<')
or Carp::croak "couldn't read file '$filename': $!";

$invocant->read_handle($handle);
}

=head2 read_string
my $hash_ref = Config::INI::Reader->read_string($string);
Given a string, this method returns a hashref of the contents of that string.
=cut

# Create an object from a string
sub read_string {
my ($invocant, $string) = @_;

Carp::croak "no string provided" unless defined $string;

my $handle = IO::String->new($string);

$invocant->read_handle($handle);
}

=head2 read_handle
my $hash_ref = Config::INI::Reader->read_handle($io_handle);
Expand Down
40 changes: 3 additions & 37 deletions lib/Config/INI/Writer.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

use strict;

use warnings;
package Config::INI::Writer;
use Mixin::Linewise::Writers;

=head1 NAME
Expand All @@ -13,7 +13,7 @@ version 0.012
=cut

$Config::INI::Writer::VERSION = '0.012';
our $VERSION = '0.012';

=head1 SYNOPSIS
Expand Down Expand Up @@ -91,11 +91,6 @@ The given data should be a hashref of hashrefs:
All the reader methods throw an exception when they encounter an error.
=cut

use IO::File;
use IO::String;

=head2 write_file
Config::INI::Writer->write_file($input, $filename);
Expand All @@ -106,42 +101,13 @@ named by C<$filename>. If a file by that name exists, it is overwritten.
This method will either succeed or raise an exception. (Its return value is
not defined.)
=cut

sub write_file {
my ($invocant, $data, $filename) = @_;

# Check the file
Carp::croak "no filename specified" unless $filename;
Carp::croak "'$filename' is not a plain file" if -e $filename && ! -f _;

# Write out the file
my $handle = IO::File->new($filename, '>')
or Carp::croak "couldn't write to file '$filename': $!";

$invocant->write_handle($data, $handle);
}

=head2 write_string
my $string = Config::INI::Writer->write_string($input);
This method returns a string containing the INI content describing the given
data.
=cut

sub write_string {
my ($invocant, $data) = @_;

my $string = '';
my $handle = IO::String->new($string);

$invocant->write_handle($data, $handle);

return $string;
}

=head2 write_handle
Config::INI::Writer->write_handle($input, $handle);
Expand Down

0 comments on commit 067ab0e

Please sign in to comment.