#!/usr/bin/env perl
#
#  This file is part of WebDyne.
#
#  This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
#
#  This is free software; you can redistribute it and/or modify it under
#  the same terms as the Perl 5 programming language system itself.
#
#  Full license text is available at:
#
#  <http://dev.perl.org/licenses/>
#


#
#  Dump the compiled version of WebDyne HTML scripts, as stored in the cache dir
#
use strict qw(vars);
use vars   qw($VERSION);


#  Use the base module
#
use WebDyne::Util;


#  External modules
#
use Getopt::Long;
use Pod::Usage;
use Data::Dumper;
use Storable;
use FindBin qw($RealBin $Script);


#  Local customisation
#
local $Data::Dumper::Indent=1;
local $Data::Dumper::Sortkeys=1;


#  Version Info, must be all one line for MakeMaker, CPAN.
#
$VERSION='3.005';


#  Run main
#
exit ${&main(\@ARGV) || die errdump()};


#============================================================================


sub main {


    #  Get argv array ref
    #
    my $argv_ar=shift();


    #  Get command line options
    #
    my %opt;
    GetOptions(
        \%opt,
        my @opt=(
        'help|?',
        'man',
        'dump_opt|dump-opt|opt',
        'version'
        )
    ) ||
        pod2usage(2);
    pod2usage(-verbose => 99, -sections => 'SYNOPSIS|OPTIONS', -exitval => 1) if $opt{'help'};
    pod2usage(-verbose => 2)                                                  if $opt{'man'};
    $opt{'version'} && do {print "$Script version: $VERSION\n"; exit 0};

    #  Dump options for debugging
    #
    die Dumper(\%opt) if $opt{'dump_opt'};

    #  Get srce file
    #
    my $srce_pn=$argv_ar->[0] ||
        pod2usage("$Script: no source file specified !");


    #  Retrieve
    #
    my $data_ar=Storable::retrieve($srce_pn);


    #  Dump
    #
    print Data::Dumper::Dumper($data_ar);


    #  Done
    #
    return \undef;


}

__END__

=begin markdown

# wddump #

# NAME #

wddump - dump the data structure of a WebDyne page in the cache directory

# SYNOPSIS #

`wddump [OPTIONS] FILE`

# Description #

The  `wddump`  command reads a compiled WebDyne Storable cache file and displays its internal data structure with `Data::Dumper`. The  `wddump`  utility is of limited diagnostic use \- the  `wdcompile`  tool is more suitable for troubleshooting HTML tree errors.

`wddump`  can be useful for inspecting the final data structure of complex pages built through multiple filters, static blocks, and dynamic blocks.

# Options #

* **--help**

    Show brief help message.

* **--man**

    Display the full manual.

* **--dump_opt**

    Dump the processed option hash and exit.

* **--version**

    Display the script version and exit.

# Examples #

```sh
# Display the data structure from a compiled, cached webdyne time.psp file. 
# File name and location will vary depending on your configuration 
#
$ wddump /var/webdyne/cache/26f2c4edc8bfd52fbde915290db96779

$VAR1 = [
  '<!DOCTYPE html><html lang="en"><head><title>Untitled Document</title><meta charset="UTF-8"><meta content="width=device-width, initial-scale=1.0" name="viewport"></head>
<body><p>The current server time is: ',
  [
    'perl',
    {
      'inline' => 1,
      'perl' => ' localtime() '
    },
    undef,
    undef,
    2,
    2,
    \'time.psp'
  ],
  '</p></body></html>'
];

```

# Author #

Andrew Speer <andrew.speer@isolutions.com.au>

# LICENSE and COPYRIGHT

This file is part of WebDyne.

This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

Full license text is available at:

<http://dev.perl.org/licenses/>


=end markdown


=head1 wddump


=head1 NAME

wddump - dump the data structure of a WebDyne page in the cache directory


=head1 SYNOPSIS

C<wddump [OPTIONS] FILE>


=head1 Description

The  C<wddump>  command reads a compiled WebDyne Storable cache file and displays its internal data structure with C<Data::Dumper>. The  C<wddump>  utility is of limited diagnostic use - the  C<wdcompile>  tool is more suitable for troubleshooting HTML tree errors.

C<wddump>  can be useful for inspecting the final data structure of complex pages built through multiple filters, static blocks, and dynamic blocks.


=head1 Options

=over

=item *

B<--help>

Show brief help message.



=item *

B<--man>

Display the full manual.



=item *

B<--dump_opt>

Dump the processed option hash and exit.



=item *

B<--version>

Display the script version and exit.



=back


=head1 Examples


 # Display the data structure from a compiled, cached webdyne time.psp file. 
 # File name and location will vary depending on your configuration 
 #
 $ wddump /var/webdyne/cache/26f2c4edc8bfd52fbde915290db96779
 
 $VAR1 = [
   '<!DOCTYPE html><html lang="en"><head><title>Untitled Document</title><meta charset="UTF-8"><meta content="width=device-width, initial-scale=1.0" name="viewport"></head>
 <body><p>The current server time is: ',
   [
     'perl',
     {
       'inline' => 1,
       'perl' => ' localtime() '
     },
     undef,
     undef,
     2,
     2,
     \'time.psp'
   ],
   '</p></body></html>'
 ];


=head1 Author

Andrew Speer L<mailto:andrew.speer@isolutions.com.au>


=head1 LICENSE and COPYRIGHT

This file is part of WebDyne.

This software is copyright (c) 2026 by Andrew Speer E<lt>andrew.speer@isolutions.com.auE<gt>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Full license text is available at:

E<lt>L<http://dev.perl.org/licenses/&gt;>

=cut
