File: attr_lazy.t

package info (click to toggle)
libdist-zilla-util-configdumper-perl 0.003007-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 296 kB
  • ctags: 7
  • sloc: perl: 285; makefile: 2
file content (82 lines) | stat: -rw-r--r-- 2,455 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
79
80
81
82
use strict;
use warnings;

use Test::More;
use Test::DZil qw( simple_ini );
use Dist::Zilla::Util::Test::KENTNL 1.001 qw( dztest );

# ABSTRACT: Make sure plugins do what they say they'll do

require Moose;
require Dist::Zilla::Role::Plugin;
require Dist::Zilla::Plugin::Bootstrap::lib;
require Dist::Zilla::Plugin::GatherDir;
require Dist::Zilla::Plugin::MetaConfig;

subtest 'unspecificied lazy' => sub {
  my $t   = dztest();
  my $pn  = 'TestPlugin';
  my $fpn = 'Dist::Zilla::Plugin::' . $pn;

  $t->add_file( 'dist.ini', simple_ini( ['Bootstrap::lib'], ['GatherDir'], ['MetaConfig'], [$pn], ) );
  $t->add_file( 'lib/Dist/Zilla/Plugin/' . $pn . '.pm', <<"EOF");
package $fpn;

use Moose qw( has around with );
use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
with 'Dist::Zilla::Role::Plugin';

has 'attr' => ( is => 'ro', 'lazy' => 1, default => sub { 'I have value, my life has meaning' } );
has 'nlattr' => ( is => 'ro', default => sub { 'nonlazy' } );

around dump_config => config_dumper(__PACKAGE__, { attrs => [qw( attr nlattr )] });

__PACKAGE__->meta->make_immutable;
no Moose;

1;
EOF

  $t->build_ok;
  $t->meta_path_deeply(
    '/x_Dist_Zilla/plugins/*/*[ key eq \'class\' and value eq \'Dist::Zilla::Plugin::TestPlugin\' ]/../*[ key eq \'config\']',
    [ { 'Dist::Zilla::Plugin::TestPlugin' => { nlattr => 'nonlazy' } } ],
    "Plugin list expected"
  );

};

subtest 'specificied lazy' => sub {
  my $t   = dztest();
  my $pn  = 'TestPlugin';
  my $fpn = 'Dist::Zilla::Plugin::' . $pn;

  $t->add_file( 'dist.ini', simple_ini( ['Bootstrap::lib'], ['GatherDir'], ['MetaConfig'], [ $pn, { attr => 'user' } ], ) );
  $t->add_file( 'lib/Dist/Zilla/Plugin/' . $pn . '.pm', <<"EOF");
package $fpn;

use Moose qw( has around with );
use Dist::Zilla::Util::ConfigDumper qw( config_dumper );
with 'Dist::Zilla::Role::Plugin';

has 'attr' => ( is => 'ro', 'lazy' => 1, default => sub { 'I have value, my life has meaning' } );
has 'nlattr' => ( is => 'ro', default => sub { 'nonlazy' } );

around dump_config => config_dumper(__PACKAGE__, { attrs => [qw( attr nlattr )] });

__PACKAGE__->meta->make_immutable;
no Moose;

1;
EOF

  $t->build_ok;
  $t->meta_path_deeply(
    '/x_Dist_Zilla/plugins/*/*[ key eq \'class\' and value eq \'Dist::Zilla::Plugin::TestPlugin\' ]/../*[ key eq \'config\']',
    [ { 'Dist::Zilla::Plugin::TestPlugin' => { attr => 'user', nlattr => 'nonlazy' } } ],
    "Plugin list expected"
  );

};
done_testing;