#!/usr/bin/perl -w

# Run on a shell like:
#   ./psize '[1, 2, { a => "foo" }'
# or:
#   ./psize 'Math::BigInt->new(123)' 't => "Total"'

use strict;
use Devel::Size::Report qw/report_size/;

my $token = shift || '"A scalar"';

my $options = shift || {};
eval (" \$options = { $options }") if !ref $options;

my $map = {
  a => 'addr',
  b => 'bytes',
  c => 'class',
  t => 'total',
  o => 'overhead',
  i => 'indend',
  l => 'left',
  h => 'head',
  s => 'summary',
  te => 'terse',
  };

# map 'a' => 'addr'
my $opt = {};
foreach my $key ( keys %$options )
  {
  my $m = $key; $m = $map->{$key} if exists $map->{$key};
  $opt->{$m} = $options->{$key};
  }

$opt->{head} =
 "Size report v$Devel::Size::Report::VERSION for '$token' =>"; 

my $eval = $token;

# make "Foo->new(1)" => "use Foo; Foo->new(1)"
$eval = "use $1; $token" if $token =~ /^\s*([\w:]+)->/;

print report_size ( eval $eval, $opt ); 
