NG.pm

filter: Statementstmt 96.6% 58 / 60 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 20 / 20 Podpod n/a totaltotal 97.5% 78 / 80 CC 1 SCAR 0.1
CC
1
Cov
97%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« NG/System.pm ↑ Summary NG/Autobox.pm »
1 package NG;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Spreadsheet::ParseExcel;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use NG::Autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use NG::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use NG::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use NG::Excel;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use NG::Excel::Cell;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use NG::Excel::Sheet;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use NG::HTTP::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use NG::EMail;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use NG::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use NG::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use NG::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 ▶use NG::System;
Subroutine BEGIN: called CC=1 SCAR=2.6
22 use NG::Time;
23 use NG::Class;
24  
25 use base 'Exporter';
26 our @EXPORT = qw(
27 local_run
28 remote_run
29 fork_run
30 taskset
31  
32 web_get
33  
34 mail_send
35 mail_get
36  
37 from_json
38 from_yaml
39 mkdir_p
40 rm_r
41 cp_r
42 read_file
43 read_dir
44 file_stat
45  
46 process_log
47 geo_ip
48  
49 db
50 now
51  
52 parse_excel
53  
54 def_class
55 );
56 our $VERSION = '0.001_05';
57  
58 sub file_stat { NG::File->fstat(@_) }
59 sub file_md5 { NG::File->md5(@_) }
60 sub cp_r { NG::File->copy(@_) }
61 sub process_log { NG::Log::process_log(@_) }
62 sub geo_ip { NG::Log::geo_ip(@_) }
63 sub def_class { NG::Class::def(@_) }
64 sub db { NG::DB->new(@_) }
65 sub now { NG::Time->now }
66 sub local_run { NG::System::local_run(@_) }
67 sub remote_run { NG::System::remote_run(@_) }
68 sub fork_run { NG::System::fork_run(@_) }
69 sub taskset { NG::System::taskset(@_) }
70 sub web_get { NG::HTTP::Client::web_get(@_) }
71 sub mail_send { NG::EMail::send(@_) }
72 sub mail_get { NG::EMail::get(@_) }
73 sub mkdir_p { NG::Dir->make(@_) }
74 sub rm_r { NG::Dir->remove(@_) }
75 sub read_dir { NG::Dir->read(@_) }
76  
77 sub read_file {
78 my ( $file, $cb ) = @_;
79 unless ( defined $cb ) {
80 open my $fh, '<', $file;
81 return do { local $/; <$fh> }
82 }
83 my $content = NG::File->read($file);
84 $cb->($content);
85 }
86  
87 sub from_yaml {
88 my $ref = YAML::XS::LoadFile(@_);
89 return ref($ref) eq 'HASH'
90 ? NG::Hashtable->new($ref)
91 : NG::Array->new($ref);
92 }
93  
94 sub from_json {
95 my $data = &read_file(@_);
96 my $ref = JSON::XS::decode_json($data);
97 return ref($ref) eq 'HASH'
98 ? NG::Hashtable->new($ref)
99 : NG::Array->new($ref);
100 }
101  
102 sub from_xml {
103 my $data = &read_file(@_);
104 my $ref = XMLin($data);
105 return ref($ref) eq 'HASH'
106 ? NG::Hashtable->new($ref)
107 : NG::Array->new($ref);
108 }
109  
110 sub parse_excel {
111 my ( $filepath, $cb ) = @_;
112 my $parser = Spreadsheet::ParseExcel->new();
113 my $workbook = $parser->parse($filepath);
114 if ( !defined $workbook ) {
115 die $parser->error() . "\n";
116 }
117 my $ng_sheet_arr = NG::Array->new;
118 for my $sheet ( $workbook->worksheets() ) {
119 my ( $row_min, $row_max ) = $sheet->row_range();
120 my ( $col_min, $col_max ) = $sheet->col_range();
121  
122 my $ng_sheet = NG::Excel::Sheet->new(
123 name => $sheet->get_name(),
124 row_count => $row_max + 1,
125 col_count => $col_max + 1,
126 );
127  
128 for my $row ( $row_min .. $row_max ) {
129 for my $col ( $col_min .. $col_max ) {
130 my $cell = $sheet->get_cell( $row, $col );
131 next unless $cell;
132  
133 my $ng_cell = NG::Excel::Cell->new( value => $cell->value(), );
134 $ng_sheet->{cells}->[$row][$col] = $ng_cell;
135 }
136 }
137 $ng_sheet_arr->push($ng_sheet);
138 }
139  
140 my $ng_excel = NG::Excel->new($ng_sheet_arr);
141 if ( defined $cb ) {
142 $cb->($ng_excel);
143 $ng_excel->save($filepath);
144 }
145 else {
146 return $ng_excel;
147 }
148 }
149  
150 sub import {
151 my $class = shift;
152 strict->import;
153 warnings->import;
154 utf8->import;
155 feature->import(':5.10');
156 Try::Tiny->import;
157 NG::Autobox::import($class);
158 $class->export_to_level( 1, $class, @EXPORT );
159 }
160  
161 1;
162  
163 __END__
« NG/System.pm ↑ Summary NG/Autobox.pm »