File: dump.t

package info (click to toggle)
libbadger-perl 0.16-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,400 kB
  • sloc: perl: 11,004; makefile: 9
file content (78 lines) | stat: -rw-r--r-- 1,843 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#============================================================= -*-perl-*-
#
# t/core/dump.t
#
# Test the Badger::Debug module.
#
# Written by Andy Wardley <abw@wardley.org>
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
#========================================================================

use strict;
use warnings;

use lib qw( ./lib ../lib ../../lib t/core/lib );
use Badger::Debug;
use Badger::Base;
use Badger::Test 
    tests => 1,
    debug => 'Badger::Debug',
    args  => \@ARGV;
    


#-----------------------------------------------------------------------
# test dump methods
#-----------------------------------------------------------------------

package My::Badger::Base;
use base 'Badger::Base';
use Badger::Debug ':debug :dump';

sub init{
    my ($self, $config) = @_;
    @$self{ keys %$config } = values %$config;
    return $self;
}

package My::Badger::One;
use base 'My::Badger::Base';
use Badger::Debug dumps => 'x y';

sub init{
    my ($self, $config) = @_;
    @$self{ keys %$config } = values %$config;
    return $self;
}

package My::Badger::Two;
use base 'My::Badger::Base';

sub NOT_dumper {
    my ($self, $indent) = @_;
    $self->dump_hash($self,$indent,'-hidden');
}

package My::Badger::Tre;
use base 'My::Badger::Base';
use Badger::Debug ':dump';

package main;

my $one = My::Badger::One->new( x => 10, y => 20, secret => 'password' );
my $two = My::Badger::Two->new( pi => 3.142, e => 2.718, one => $one, hidden => 'treasure' );
my $tre = My::Badger::Tre->new( 
    two    => $two,
    person => { 
        name  => 'Arthur Dent', 
        email => 'dent@tt2.org',
    },
    products => ['widget123', 'doodah99'],
);

my $text = $tre->dump;
#print $text;
like( $text, qr/one => \{\s+x => 10,\s+y => 20\s+\}/, 'partial dump of one' );