#!/usr/bin/perl -w

# Run on a shell like:
# psize "Math::BigInt->new(123)"

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',
  };

# map 'a' => 'addr'
my $opt = {};
foreach my $key ( keys %$options )
  {
  if (length($key) != 1)
    {
    $opt->{$key} = $options->{$key};
    }
  else
    {
    $opt->{$map->{$key}} = $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 ); 
