| 1 | BEGIN | ||
| 2 | { | ||
| 3 | 3 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 0 | ▶ | sub UNIVERSAL::dump : method |
|
Subroutine
dump: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 6 | { | ||
| 7 | 0 | return Data::Dumper->Dump( [ shift ] ); | |
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | 3 | ▶ | use Class::Maker qw(:all); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 0 | ▶ | use File::Find::Rule; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 14 | |||
| 15 | use HTML::Mason; | ||
| 16 | |||
| 17 | use Path::Class; | ||
| 18 | |||
| 19 | use Carp qw(croak); | ||
| 20 | |||
| 21 | { | ||
| 22 | package Workflow::Aline::Fundamental; | ||
| 23 | |||
| 24 | Class::Maker::class | ||
| 25 | { | ||
| 26 | isa => [qw( Class::Listener )], | ||
| 27 | |||
| 28 | public => | ||
| 29 | { | ||
| 30 | int => [qw( stages current_stage )], | ||
| 31 | |||
| 32 | bool => [qw( is_testrun is_staging )], | ||
| 33 | |||
| 34 | array => [qw( stage_history robots )], | ||
| 35 | |||
| 36 | hash => [qw( stage_callbacks action_callbacks )], | ||
| 37 | }, | ||
| 38 | |||
| 39 | private => | ||
| 40 | { | ||
| 41 | ref => [qw( cursor )], | ||
| 42 | }, | ||
| 43 | }; | ||
| 44 | } | ||
| 45 | |||
| 46 | { | ||
| 47 | package Workflow::Aline::OnMemory; | ||
| 48 | |||
| 49 | use IO::Extended ':all'; | ||
| 50 | |||
| 51 | Class::Maker::class | ||
| 52 | { | ||
| 53 | isa => [qw( Workflow::Aline::Fundamental )], | ||
| 54 | |||
| 55 | public => | ||
| 56 | { | ||
| 57 | ref => [qw( input )], | ||
| 58 | }, | ||
| 59 | |||
| 60 | private => | ||
| 61 | { | ||
| 62 | }, | ||
| 63 | }; | ||
| 64 | |||
| 65 | sub run : method | ||
| 66 | { | ||
| 67 | my $this = shift; | ||
| 68 | |||
| 69 | my @robots = @_; | ||
| 70 | |||
| 71 | |||
| 72 | map { $_->aline( $this ) } @robots; | ||
| 73 | |||
| 74 | $this->is_staging = 1; | ||
| 75 | |||
| 76 | println "Entering multistage publishing"; | ||
| 77 | |||
| 78 | @{ $this->stage_history } = (); | ||
| 79 | |||
| 80 | for( 0 .. $this->stages ) | ||
| 81 | { | ||
| 82 | println "\n"; | ||
| 83 | |||
| 84 | printfln "stage...%d", $_; | ||
| 85 | |||
| 86 | $this->current_stage( $_ ); | ||
| 87 | |||
| 88 | my $master = $this; | ||
| 89 | |||
| 90 | my $factory_switches = Workflow::Aline::ConveyorBelt::Factory->new( | ||
| 91 | shall_create => 'Workflow::Aline::ConveyorBelt::Switch', | ||
| 92 | mixin_classes => [qw(Workflow::Aline::Pluggable::OneProximalOneDistal)] | ||
| 93 | ); | ||
| 94 | |||
| 95 | my $conveyor_belt = $factory_switches->create_new( | ||
| 96 | #proximal => $line->{$_-1}, distal => $line->{$_+1} | ||
| 97 | |||
| 98 | robots => \@robots, | ||
| 99 | |||
| 100 | master => $master, | ||
| 101 | |||
| 102 | #source_dir => ( $this->stage_history->[-1] || $this->source_dir ), | ||
| 103 | |||
| 104 | #target_dir => $this->sprintf_current_target_dir( $this->current_stage ), | ||
| 105 | |||
| 106 | ); | ||
| 107 | |||
| 108 | #$conveyor_belt->plug; | ||
| 109 | |||
| 110 | foreach ( $this->robots ) | ||
| 111 | { | ||
| 112 | last if $_->Class::Listener::signal( 'pre_session', $this, $conveyor_belt ); | ||
| 113 | } | ||
| 114 | |||
| 115 | $conveyor_belt->run; | ||
| 116 | |||
| 117 | foreach ( $this->robots ) | ||
| 118 | { | ||
| 119 | last if $_->Class::Listener::signal( 'post_session', $this ); | ||
| 120 | } | ||
| 121 | |||
| 122 | push @{ $this->stage_history }, $this->sprintf_current_target_dir( $this->current_stage ); | ||
| 123 | } | ||
| 124 | |||
| 125 | println "\nDumping stage history:"; | ||
| 126 | |||
| 127 | println for @{ $this->stage_history }; | ||
| 128 | |||
| 129 | println "\nStaging to final target"; | ||
| 130 | |||
| 131 | $this->is_staging = 0; | ||
| 132 | |||
| 133 | my $factory_ends = Workflow::Aline::ConveyorBelt::Factory->new( | ||
| 134 | shall_create => 'Workflow::Aline::ConveyorBelt::End', | ||
| 135 | |||
| 136 | mixin_classes => [qw(Workflow::Aline::Pluggable::OneProximalOneDistal)] | ||
| 137 | ); | ||
| 138 | |||
| 139 | # MUENALAN: Missing, comment why this is not plug'ed ? | ||
| 140 | |||
| 141 | $factory_ends->create_new( | ||
| 142 | robots => \@robots, | ||
| 143 | |||
| 144 | master => $this, | ||
| 145 | |||
| 146 | source_dir => $this->stage_history->[-1], | ||
| 147 | |||
| 148 | target_dir => $this->sprintf_current_target_dir | ||
| 149 | |||
| 150 | )->run; | ||
| 151 | |||
| 152 | foreach ( $this->robots ) | ||
| 153 | { | ||
| 154 | last if $_->Class::Listener::signal( 'final', $this ); | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | } | ||
| 159 | |||
| 160 | { | ||
| 161 | package Workflow::Aline; | ||
| 162 | |||
| 163 | our $VERSION = '0.04'; | ||
| 164 | |||
| 165 | our $DEBUG = { basic => 0, robots => 0 }; | ||
| 166 | |||
| 167 | use strict; | ||
| 168 | |||
| 169 | use warnings; | ||
| 170 | |||
| 171 | use IO::Extended ':all'; | ||
| 172 | |||
| 173 | use Class::Maker qw(:all); | ||
| 174 | |||
| 175 | use File::Find::Rule; | ||
| 176 | |||
| 177 | use HTML::Mason; | ||
| 178 | |||
| 179 | use Path::Class; | ||
| 180 | |||
| 181 | use Carp qw(croak); | ||
| 182 | |||
| 183 | } | ||
| 184 | |||
| 185 | use Workflow::Aline::Manager; | ||
| 186 | use Workflow::Aline::Robot; | ||
| 187 | use Workflow::Aline::Pluggable; | ||
| 188 | use Workflow::Aline::ConveyorBelt; | ||
| 189 | |||
| 190 | { | ||
| 191 | package Workflow::Aline; | ||
| 192 | |||
| 193 | use IO::Extended qw(:all); | ||
| 194 | |||
| 195 | use Data::Iter qw(:all); | ||
| 196 | |||
| 197 | use modules qw( File::Spec File::Path File::Basename Carp ); | ||
| 198 | |||
| 199 | # We load a patched File::Find | ||
| 200 | |||
| 201 | Class::Maker::class | ||
| 202 | { | ||
| 203 | isa => [qw( Workflow::Aline::Fundamental )], | ||
| 204 | |||
| 205 | public => | ||
| 206 | { | ||
| 207 | ref => [qw( home_dir source_dir target_dir comp_dir temp_dir )], | ||
| 208 | |||
| 209 | string => [qw( stage_dir_format )], | ||
| 210 | }, | ||
| 211 | |||
| 212 | default => | ||
| 213 | { | ||
| 214 | temp_dir => Path::Class::Dir->new( '_publish' ), | ||
| 215 | |||
| 216 | stage_dir_format => '_stage%d', | ||
| 217 | |||
| 218 | current_stage => 0, | ||
| 219 | |||
| 220 | stages => 1, | ||
| 221 | |||
| 222 | is_testrun => 0, | ||
| 223 | }, | ||
| 224 | }; | ||
| 225 | |||
| 226 | our $mason_interp; | ||
| 227 | |||
| 228 | { | ||
| 229 | package HTML::Mason::Commands; | ||
| 230 | |||
| 231 | use Data::Iter qw(:all); | ||
| 232 | |||
| 233 | use Class::Maker qw(:all); | ||
| 234 | |||
| 235 | use IO::Extended qw(:all); | ||
| 236 | |||
| 237 | use Data::Dumper; | ||
| 238 | |||
| 239 | our $dtq; | ||
| 240 | } | ||
| 241 | |||
| 242 | sub _postinit : method | ||
| 243 | { | ||
| 244 | my $this = shift; | ||
| 245 | |||
| 246 | foreach( qw(source_dir target_dir home_dir comp_dir temp_dir) ) | ||
| 247 | { | ||
| 248 | confess "$this->$_ is not defined" unless defined( $this->$_ ); | ||
| 249 | |||
| 250 | $this->$_( Path::Class::Dir->new( $this->$_ ) ) unless ref( $this->$_ ); #->isa( 'Path::Class::Dir' ); | ||
| 251 | } | ||
| 252 | |||
| 253 | foreach ( qw( source_dir target_dir temp_dir ) ) | ||
| 254 | { | ||
| 255 | $this->$_->cleanup; | ||
| 256 | |||
| 257 | unless( -e $this->$_ ) | ||
| 258 | { | ||
| 259 | warnfln "$this->_postinit: Did not find %s ..making dir.", $this->$_; | ||
| 260 | |||
| 261 | $this->$_->mkpath; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | warn "Mason (init):"; | ||
| 266 | |||
| 267 | indn; | ||
| 268 | |||
| 269 | for( iter { module => $this->comp_dir->stringify, basic => $this->home_dir->stringify } ) | ||
| 270 | { | ||
| 271 | warnfln "Mason (comp dirs): %s => %s", KEY, VALUE; | ||
| 272 | } | ||
| 273 | |||
| 274 | indb; | ||
| 275 | |||
| 276 | $Workflow::Aline::mason_interp = HTML::Mason::Interp->new( | ||
| 277 | |||
| 278 | comp_root => # like @INC - first gets searched first | ||
| 279 | [ | ||
| 280 | [ module => $this->comp_dir->stringify ], # ongoing stage? | ||
| 281 | [ basic => $this->home_dir->stringify ], # /basic/*.mas | ||
| 282 | ], | ||
| 283 | |||
| 284 | allow_globals => [ '$dtq' ], | ||
| 285 | |||
| 286 | #resolver_class => 'HTML::Mason::Resolver::FileDebug', | ||
| 287 | ); | ||
| 288 | |||
| 289 | $this->is_staging( 0 ); | ||
| 290 | } | ||
| 291 | |||
| 292 | sub new_with_setup : method | ||
| 293 | { | ||
| 294 | my $this = shift; | ||
| 295 | |||
| 296 | our %options = | ||
| 297 | ( | ||
| 298 | home_dir => Path::Class::Dir->new( '.aline' )->absolute, | ||
| 299 | |||
| 300 | project => 'test1', | ||
| 301 | ); | ||
| 302 | |||
| 303 | my %args = @_; | ||
| 304 | |||
| 305 | %options = ( %options, %args ); | ||
| 306 | |||
| 307 | $options{home_dir} = Path::Class::Dir->new( $options{home_dir} ) unless ref( $options{home_dir} ); | ||
| 308 | |||
| 309 | $options{home_dir} = $options{home_dir}->absolute; | ||
| 310 | |||
| 311 | my $aline = Workflow::Aline->new( | ||
| 312 | |||
| 313 | source_dir => Path::Class::Dir->new( $options{home_dir}, 'projects', $options{project}, 'files' ), | ||
| 314 | |||
| 315 | target_dir => Path::Class::Dir->new( $options{home_dir}, 'projects', $options{project}, 'published' ), | ||
| 316 | |||
| 317 | home_dir => $options{home_dir}, | ||
| 318 | |||
| 319 | comp_dir => Path::Class::Dir->new( $options{home_dir}, 'projects', $options{project} ), | ||
| 320 | |||
| 321 | temp_dir => Path::Class::Dir->new( $options{home_dir}, 'projects', $options{project}, '_temp' ), | ||
| 322 | |||
| 323 | is_testrun => 0, | ||
| 324 | |||
| 325 | stages => 2, | ||
| 326 | |||
| 327 | stage_dir_format => Path::Class::Dir->new( 'stage%d' )->stringify, | ||
| 328 | |||
| 329 | robots => | ||
| 330 | [ | ||
| 331 | Workflow::Aline::Robot::Finalize->new( aline => $this ), | ||
| 332 | ], | ||
| 333 | ); | ||
| 334 | |||
| 335 | return $aline; | ||
| 336 | } | ||
| 337 | |||
| 338 | sub _on_copy : method | ||
| 339 | { | ||
| 340 | my $this = shift; | ||
| 341 | |||
| 342 | |||
| 343 | my $logfile = $this->home_dir->file( 'aline.log' ); | ||
| 344 | |||
| 345 | open( LOG, sprintf ">>%s", $logfile ) or die "cant open $logfile"; | ||
| 346 | |||
| 347 | printf LOG "$_\n" for @_; | ||
| 348 | |||
| 349 | close( LOG ); | ||
| 350 | } | ||
| 351 | |||
| 352 | sub sprintf_stage_dir : method | ||
| 353 | { | ||
| 354 | my $this = shift; | ||
| 355 | |||
| 356 | my $stage = shift || 0; | ||
| 357 | |||
| 358 | return $this->temp_dir->subdir( Path::Class::Dir->new( sprintf( $this->stage_dir_format, $stage ) ) ); | ||
| 359 | } | ||
| 360 | |||
| 361 | sub sprintf_current_target_dir : method | ||
| 362 | { | ||
| 363 | my $this = shift; | ||
| 364 | |||
| 365 | my $stage = shift; | ||
| 366 | |||
| 367 | if( $this->is_staging ) | ||
| 368 | { | ||
| 369 | defined $stage or Workflow::Aline::croak "expected argument to sprintf_current_target_dir"; | ||
| 370 | |||
| 371 | my $d = $this->sprintf_stage_dir( $stage ); | ||
| 372 | |||
| 373 | unless( -e $d ) | ||
| 374 | { | ||
| 375 | warnfln "$this->sprintf_current_target_dir: Did not find %s ..making dir.", $d; | ||
| 376 | |||
| 377 | $d->mkpath; | ||
| 378 | } | ||
| 379 | |||
| 380 | return $d; | ||
| 381 | } | ||
| 382 | |||
| 383 | return $this->target_dir; | ||
| 384 | } | ||
| 385 | |||
| 386 | sub run : method | ||
| 387 | { | ||
| 388 | my $this = shift; | ||
| 389 | |||
| 390 | my @robots = @_; | ||
| 391 | |||
| 392 | |||
| 393 | map { $_->aline( $this ) } @robots; | ||
| 394 | |||
| 395 | $this->is_staging = 1; | ||
| 396 | |||
| 397 | println "Entering multistage publishing"; | ||
| 398 | |||
| 399 | @{ $this->stage_history } = (); | ||
| 400 | |||
| 401 | for( 0 .. $this->stages ) | ||
| 402 | { | ||
| 403 | println "\n"; | ||
| 404 | |||
| 405 | printfln "stage...%d", $_; | ||
| 406 | |||
| 407 | $this->current_stage( $_ ); | ||
| 408 | |||
| 409 | # print Data::Dumper->Dump( [ $this ] ); | ||
| 410 | |||
| 411 | #println ref($_) for $this->robots; | ||
| 412 | |||
| 413 | my $master = $this; | ||
| 414 | |||
| 415 | my $factory_switches = Workflow::Aline::ConveyorBelt::Factory->new( | ||
| 416 | shall_create => 'Workflow::Aline::ConveyorBelt::Switch', | ||
| 417 | mixin_classes => [qw(Workflow::Aline::Pluggable::OneProximalOneDistal)] | ||
| 418 | ); | ||
| 419 | |||
| 420 | my $conveyor_belt = $factory_switches->create_new( | ||
| 421 | #proximal => $line->{$_-1}, distal => $line->{$_+1} | ||
| 422 | |||
| 423 | robots => \@robots, | ||
| 424 | |||
| 425 | master => $master, | ||
| 426 | |||
| 427 | source_dir => ( $this->stage_history->[-1] || $this->source_dir ), | ||
| 428 | |||
| 429 | target_dir => $this->sprintf_current_target_dir( $this->current_stage ), | ||
| 430 | |||
| 431 | ); | ||
| 432 | |||
| 433 | #$conveyor_belt->plug; | ||
| 434 | |||
| 435 | foreach ( $this->robots ) | ||
| 436 | { | ||
| 437 | last if $_->Class::Listener::signal( 'pre_session', $this, $conveyor_belt ); | ||
| 438 | } | ||
| 439 | |||
| 440 | $conveyor_belt->run; | ||
| 441 | |||
| 442 | foreach ( $this->robots ) | ||
| 443 | { | ||
| 444 | last if $_->Class::Listener::signal( 'post_session', $this ); | ||
| 445 | } | ||
| 446 | |||
| 447 | push @{ $this->stage_history }, $this->sprintf_current_target_dir( $this->current_stage ); | ||
| 448 | } | ||
| 449 | |||
| 450 | println "\nDumping stage history:"; | ||
| 451 | |||
| 452 | println for @{ $this->stage_history }; | ||
| 453 | |||
| 454 | println "\nStaging to final target"; | ||
| 455 | |||
| 456 | $this->is_staging = 0; | ||
| 457 | |||
| 458 | my $factory_ends = Workflow::Aline::ConveyorBelt::Factory->new( | ||
| 459 | shall_create => 'Workflow::Aline::ConveyorBelt::End', | ||
| 460 | |||
| 461 | mixin_classes => [qw(Workflow::Aline::Pluggable::OneProximalOneDistal)] | ||
| 462 | ); | ||
| 463 | |||
| 464 | # MUENALAN: Missing, comment why this is not plug'ed ? | ||
| 465 | |||
| 466 | $factory_ends->create_new( | ||
| 467 | robots => \@robots, | ||
| 468 | |||
| 469 | master => $this, | ||
| 470 | |||
| 471 | source_dir => $this->stage_history->[-1], | ||
| 472 | |||
| 473 | target_dir => $this->sprintf_current_target_dir | ||
| 474 | |||
| 475 | )->run; | ||
| 476 | |||
| 477 | foreach ( $this->robots ) | ||
| 478 | { | ||
| 479 | last if $_->Class::Listener::signal( 'final', $this ); | ||
| 480 | } | ||
| 481 | } | ||
| 482 | |||
| 483 | sub close : method | ||
| 484 | { | ||
| 485 | my $this = shift; | ||
| 486 | |||
| 487 | foreach ( $this->robots ) | ||
| 488 | { | ||
| 489 | last if $_->Class::Listener::signal( 'close', $this ); | ||
| 490 | } | ||
| 491 | |||
| 492 | if( -e $this->temp_dir ) | ||
| 493 | { | ||
| 494 | warnfln "$this->close: Cleaning %s ..deleting files.", $this->temp_dir; | ||
| 495 | |||
| 496 | $this->temp_dir->rmtree( 1, 1 ); | ||
| 497 | } | ||
| 498 | |||
| 499 | printfln "\n\nYou can now find your published files in %S\n\n", $this->target_dir; | ||
| 500 | } | ||
| 501 | } | ||
| 502 | |||
| 503 | 1; | ||
| 504 | __END__ | ||