LDAP/Role/Command.pm

filter: Statementstmt 68.9% 20 / 29 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 3 / 3 totaltotal 67.4% 29 / 43 CC 2 SCAR 7.9
CC
2
Cov
65%
new_password
6.0
prepare
2.0
encrypt
2.0
CRAP 2.2
« LDAP/Command/Del/User.pm ↑ Summary LDAP/Role.pm »
1 package App::LDAP::Role::Command;
2  
3 =head1 NAME
4  
5 App::LDAP::Role::Command - make a class act as a command
6  
7 =head1 SYNOPSIS
8  
9 package App::LDAP::Command::YourCommand;
10 use Moose;
11 with 'App::LDAP::Role::Command';
12  
13 has foo => (
14 is => "rw",
15 isa => "Str",
16 );
17  
18 around prepare => sub {
19 my $orig = shift;
20 my $self = shift;
21  
22 # hook some actions
23  
24 $self->$orig(@_);
25 };
26  
27 sub run {
28 my $self = shift;
29 # do something
30 }
31  
32 package main;
33 App::LDAP::Command::YourCommand->new_with_options()->prepare()->new();
34  
35 =head1 DESCRIPTION
36  
37 This role should be included in any module aimed at being a handler in App::LDAP. It mixs the MooseX::Getopt and
38 App::LDAP::Role and defines the wrappers to Namespace::Dispatch. That is, a command can declare the acceptable options
39 as describing in MooseX::Getopt, invoking helpers from App::LDAP::Role, and dispatching like 'use Namespace::Dispatch'.
40  
41 =cut
42  
43 8 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 8 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 8 with qw( MooseX::Getopt::Dashes
46 App::LDAP::Role );
47  
48 =head1 METHODS
49  
50 =head2 prepare()
51  
52 the instance method invoked before running.
53  
54 $class->new_with_options()->prepare()->run()
55  
56 this method is designed to be hooked with 'around' in Moose and just returns the instance itself here.
57  
58 =cut
59  
60 0 ▶sub prepare {
Subroutine prepare: not called CC=1 SCAR=6.9
Pod documented
61 0 my $self = shift;
62 0 return $self;
63 }
64  
65 8 ▶use Namespace::Dispatch;
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 =head2 dispatch()
68  
69 the wrapper of Namespace::Dispatch::dispatch()
70  
71 $class->dispatch(@consequences)
72  
73 =head2 has_leaf()
74  
75 the wrapper of Namespace::Dispatch::has_leaf()
76  
77 $class->has_leaf('name');
78  
79 =head2 leaves
80  
81 the wrapper of Namespace::Dispatch::leaves()
82  
83 $submodules = $class->leaves();
84  
85 =head2 encrypt($plain)
86  
87 given a plain text password, the helper returns an encrypted one.
88  
89 $hashed = encrypt($plain);
90  
91 =cut
92  
93 8 ▶use Crypt::Password;
Subroutine BEGIN: called CC=1 SCAR=0.0
94 0 ▶sub encrypt {
Subroutine encrypt: not called CC=1 SCAR=6.9
Pod documented
95 0 my $plain = shift;
96 0 "{crypt}".password($plain, undef, "sha512");
97 }
98  
99 =head2 new_password()
100  
101 read and confirm the new password from terminal.
102 die if failing to confirm.
103  
104 $plain = new_password();
105  
106 =cut
107  
108 8 ▶use Term::ReadPassword;
Subroutine BEGIN: called CC=1 SCAR=0.0
109 0 ▶sub new_password {
Subroutine new_password: not called CC=2 SCAR=17.9
Pod documented
110 0 my $password = read_password("password: ");
111 0 my $comfirm = read_password("comfirm password: ");
112  
113 0 ▶ if ($password eq $comfirm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($password eq $comfirm) { } 0 0 0
114 0 return $password;
115 } else {
116 0 die "not the same";
117 }
118 }
119  
120 8 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
121  
122 8 1;
« LDAP/Command/Del/User.pm ↑ Summary LDAP/Role.pm »