File Coverage

blib/lib/Module/Faker/Package.pm
Criterion Covered Total %
statement 20 27 74.0
branch 4 10 40.0
condition n/a
subroutine 5 7 71.4
pod 0 1 0.0
total 29 45 64.4


line stmt bran cond sub pod time code
1             package Module::Faker::Package 0.023;
2             # ABSTRACT: a faked package in a faked module
3              
4 8     8   82 use Moose;
  8         24  
  8         78  
5              
6 8     8   55063 use Moose::Util::TypeConstraints;
  8         18  
  8         62  
7              
8             has name => (is => 'ro', isa => 'Str', required => 1);
9             has version => (is => 'ro', isa => 'Maybe[Str]');
10             has abstract => (is => 'ro', isa => 'Maybe[Str]');
11             has style => (is => 'ro', default => 'legacy');
12              
13             has in_file => (
14             is => 'ro',
15             isa => 'Str',
16             lazy => 1,
17             default => sub {
18             my ($self) = @_;
19             my $name = $self->name;
20             $name =~ s{::}{/}g;
21             return "lib/$name";
22             },
23             );
24              
25             sub _format_legacy {
26 36     36   108 my ($self) = @_;
27              
28 36         69 my $string = q{};
29              
30 36         974 $string .= sprintf "package %s;\n", $self->name;
31 36 100       995 $string .= sprintf "our \$VERSION = '%s';\n", $self->version
32             if defined $self->version;
33              
34 36         210 return $string;
35             }
36              
37             sub _format_statement {
38 0     0   0 my ($self) = @_;
39              
40 0         0 my $string = q{};
41              
42 0 0       0 $string .= sprintf "package %s%s;\n",
43             $self->name,
44             (defined $self->version ? (q{ } . $self->version) : '');
45              
46 0         0 return $string;
47             }
48              
49             sub _format_block {
50 0     0   0 my ($self) = @_;
51              
52 0 0       0 my $string = sprintf "package %s%s {\n\n # Your code here\n\n}\n",
53             $self->name,
54             (defined $self->version ? (q{ } . $self->version) : '');
55              
56 0         0 return $string;
57             }
58              
59             sub as_string {
60 36     36 0 83 my ($self) = @_;
61              
62 36         982 my $style = $self->style;
63              
64 36 50       112 unless (ref $style) {
65 36 50       183 confess("unknown package style: $style") unless $self->can("_format_$style");
66 36         95 $style = "_format_$style";
67             }
68              
69 36         115 return $self->$style;
70             }
71              
72             subtype 'Module::Faker::Type::Packages'
73             => as 'ArrayRef[Module::Faker::Package]';
74              
75 8     8   22008 no Moose;
  8         33  
  8         39  
76             1;
77              
78             __END__
79              
80             =pod
81              
82             =encoding UTF-8
83              
84             =head1 NAME
85              
86             Module::Faker::Package - a faked package in a faked module
87              
88             =head1 VERSION
89              
90             version 0.023
91              
92             =head1 PERL VERSION
93              
94             This module should work on any version of perl still receiving updates from
95             the Perl 5 Porters. This means it should work on any version of perl released
96             in the last two to three years. (That is, if the most recently released
97             version is v5.40, then this module should work on both v5.40 and v5.38.)
98              
99             Although it may work on older versions of perl, no guarantee is made that the
100             minimum required version will not be increased. The version may be increased
101             for any reason, and there is no promise that patches will be accepted to lower
102             the minimum required perl.
103              
104             =head1 AUTHOR
105              
106             Ricardo Signes <cpan@semiotic.systems>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is copyright (c) 2008 by Ricardo Signes.
111              
112             This is free software; you can redistribute it and/or modify it under
113             the same terms as the Perl 5 programming language system itself.
114              
115             =cut