Permalink
Browse files

API matching

  • Loading branch information...
1 parent 3388920 commit 80eb47deca233d62fd4d5b2ce484756f512f5f35 @kentfredric kentfredric committed Jul 5, 2009
@@ -13,15 +13,11 @@ class ELF::Extract::Sections with MooseX::Log::Log4perl {
require ELF::Extract::Sections::Section;
- has file => ( ro, required, isa => File, coerce => 1, );
-
- has sections => ( isa => HashRef [ElfSection], ro, lazy_build, );
-
+ has file => ( isa => File, ro, required, coerce, );
has scanner => ( isa => Str, default => 'Objdump', ro, );
-
- has _scanner_package => ( isa => ClassName, ro, lazy_build, );
-
- has _scanner_instance => ( isa => Object, ro, lazy_build, );
+ has sections => ( isa => HashRef [ElfSection], ro, lazy_build, );
+ has _scanner_package => ( isa => ClassName, ro, lazy_build, );
+ has _scanner_instance => ( isa => Object, ro, lazy_build, );
#
# Public Interfaces
@@ -32,10 +28,7 @@ class ELF::Extract::Sections with MooseX::Log::Log4perl {
#>>>
my $m = 1;
$m = -1 if ($descending);
- return [
- sort { $m * ( $a->compare( other => $b, field => $field ) ) }
- values %{ $self->sections }
- ];
+ return [ sort { $m * ( $a->compare( other => $b, field => $field ) ) } values %{ $self->sections } ];
};
#
@@ -45,9 +38,7 @@ class ELF::Extract::Sections with MooseX::Log::Log4perl {
method _build__scanner_package {
my $pkg = 'ELF::Extract::Sections::Scanner::' . $self->scanner;
eval "use $pkg; 1"
- or $self->log->logconfess( "The Scanner "
- . $self->scanner
- . " could not be found as $pkg. >$! >$@ " );
+ or $self->log->logconfess( "The Scanner " . $self->scanner . " could not be found as $pkg. >$! >$@ " );
return $pkg;
};
@@ -114,11 +105,7 @@ class ELF::Extract::Sections with MooseX::Log::Log4perl {
my @k = sort { $a <=> $b } keys %{$ob};
my $i = 0;
while ( $i < $#k ) {
- $dataStash{ $ob->{ $k[$i] } } = $self->_build_section_section(
- $ob->{ $k[$i] },
- $k[$i], $k[ $i + 1 ],
- $self->file
- );
+ $dataStash{ $ob->{ $k[$i] } } = $self->_build_section_section( $ob->{ $k[$i] }, $k[$i], $k[ $i + 1 ], $self->file );
$i++;
}
return \%dataStash;
@@ -143,9 +130,7 @@ class ELF::Extract::Sections with MooseX::Log::Log4perl {
my $offset = $self->_scanner_instance->section_offset;
my $size = $self->_scanner_instance->section_size;
- $dataStash{$name} =
- $self->_build_section_section( $name, $offset, $offset + $size,
- $self->file );
+ $dataStash{$name} = $self->_build_section_section( $name, $offset, $offset + $size, $self->file );
}
return \%dataStash;
};
@@ -10,11 +10,7 @@ role ELF::Extract::Sections::Meta::Scanner with MooseX::Log::Log4perl {
our $VERSION = '0.0103';
- requires(
- 'open_file', 'next_section',
- 'section_offset', 'section_size',
- 'section_name', 'can_compute_size'
- );
+ requires( 'open_file', 'next_section', 'section_offset', 'section_size', 'section_name', 'can_compute_size' );
}
1;
@@ -8,7 +8,7 @@ use Moose;
our $VERSION = '0.0103';
use MooseX::Types::Moose (':all');
-use MooseX::Types -declare => [ 'FilterField','ElfSection'];
+use MooseX::Types -declare => [ 'FilterField', 'ElfSection' ];
subtype FilterField, as enum( [ 'name', 'offset', 'size', ] );
@@ -9,40 +9,15 @@ with ELF::Extract::Sections::Meta::Scanner {
#>>>
our $VERSION = '0.0103';
use MooseX::Has::Sugar 0.0300;
- use MooseX::Types::Moose qw( Bool HashRef RegexpRef FileHandle );
- use MooseX::Types::Path::Class qw( File );
-
- has _header_regex => (
- isa => RegexpRef,
- ro,
- default => sub {
- return qr/<(?<header>[^>]+)>/;
- },
- );
-
- has _offset_regex => (
- isa => RegexpRef,
- ro,
- default => sub {
- return qr/\(File Offset:\s*(?<offset>0x[0-9a-f]+)\)/;
- },
- );
-
- has _section_header_identifier => ( isa => RegexpRef, ro, lazy_build, );
+ use MooseX::Types::Moose ( 'Bool', 'HashRef', 'RegexpRef', 'FileHandle', );
+ use MooseX::Types::Path::Class ('File');
- has _file => ( isa => File, rw, clearer => '_clear_file', );
-
- has _filehandle => (
- isa => FileHandle,
- rw, clearer => '_clear_filehandle',
- );
-
- has _state => (
- isa => HashRef,
- rw,
- predicate => '_has_state',
- clearer => '_clear_state',
- );
+ has _header_regex => ( isa => RegexpRef, ro, default => sub { return qr/<(?<header>[^>]+)>/; }, );
+ has _offset_regex => ( isa => RegexpRef, ro, default => sub { return qr/\(File Offset:\s*(?<offset>0x[0-9a-f]+)\)/; }, );
+ has _section_header_identifier => ( isa => RegexpRef, ro, lazy_build, );
+ has _file => ( isa => File, rw, clearer => '_clear_file', );
+ has _filehandle => ( isa => FileHandle, rw, clearer => '_clear_filehandle', );
+ has _state => ( isa => HashRef, rw, predicate => '_has_state', clearer => '_clear_state', );
#
# Interface Methods
@@ -75,22 +50,19 @@ with ELF::Extract::Sections::Meta::Scanner {
method section_offset {
if ( not $self->_has_state ) {
- $self->log->logcroak(
- 'Invalid call to section_offset outside of file scan');
+ $self->log->logcroak('Invalid call to section_offset outside of file scan');
return;
}
return hex( $self->_state->{offset} );
};
method section_size {
- $self->log->logcroak(
- 'Can\'t perform section_size on this type of object.');
+ $self->log->logcroak('Can\'t perform section_size on this type of object.');
};
method section_name {
if ( not $self->_has_state ) {
- $self->log->logcroak(
- 'Invalid call to section_name outside of file scan');
+ $self->log->logcroak('Invalid call to section_name outside of file scan');
}
return $self->_state->{header};
};
@@ -117,13 +89,10 @@ with ELF::Extract::Sections::Meta::Scanner {
#<<<
method _objdump {
#>>>
- if ( open my $fh,
- '-|', 'objdump', qw( -D -F ), $self->_file->cleanup->absolute )
- {
+ if ( open my $fh, '-|', 'objdump', qw( -D -F ), $self->_file->cleanup->absolute ) {
return $fh;
}
- $self->log->logconfess(
- qq{An error occured requesting section data from objdump $^ $@ });
+ $self->log->logconfess(qq{An error occured requesting section data from objdump $^ $@ });
return;
#<<<
};
@@ -11,25 +11,17 @@ class ELF::Extract::Sections::Section {
use overload '""' => \&to_string;
- has source => (
- isa => File,
- ro, required, coerce => 1,
- );
-
- has name => ( isa => Str, ro, required );
-
- has offset => ( isa => Int, ro, required );
-
- has size => ( isa => Int, ro, required );
+ has source => ( isa => File, ro, required, coerce, );
+ has name => ( isa => Str, ro, required );
+ has offset => ( isa => Int, ro, required );
+ has size => ( isa => Int, ro, required );
#<<<
method to_string ( Any $other?, Bool $polarity? ) {
#>>>
return sprintf(
qq{[ Section %s of size %s in %s @ %x to %x ]},
- $self->name, $self->size,
- $self->source, $self->offset,
- $self->offset + $self->size,
+ $self->name, $self->size, $self->source, $self->offset, $self->offset + $self->size,
);
};
@@ -57,7 +49,7 @@ class ELF::Extract::Sections::Section {
my $output = $file->openw;
my $chunksize = 1024;
my $bytes_left = $self->size;
- my $chunk = ( $bytes_left < $chunksize ) ? $bytes_left : $chunksize;
+ my $chunk = ( $bytes_left < $chunksize ) ? $bytes_left : $chunksize;
while ( read( $fh, my $buffer, $chunk ) ) {
print {$output} $buffer;
$bytes_left -= $chunksize;

0 comments on commit 80eb47d

Please sign in to comment.